# C Program to print Twin prime numbers between two ranges

## What are Twin Primes Numbers?

Pair of prime numbers which differ by 2 is called Twin Prime. For example, the first 4 twin primes are:

(3, 5), (11, 13), (17, 19), (29, 31)

The following is a C program to print Twin prime numbers between two ranges:

Expected Output:

1st run:

2nd run:

## How it works

In line 19, we have a for loop that iterates over the numbers between the specified range.

In line 21, we call `check_prime()` number two times. Once with the number `i` and once with the number `i + 2`.

If the condition satisfies then `i` and `i + 2` are twin primes. In line 23, we print the twin prime numbers and in line 24, we increment the counter `i` by `1`, to check for the next number.

### 4 thoughts on “C Program to print Twin prime numbers between two ranges”

1. Your code has a mistake. Where is the 5 and 7 pair?

• Code is rectified. Thanks for pointing out!

2. Enter start: 1
Enter end: 50
{3, 5}
{11, 13}
{17, 19}
{29, 31}
{41, 43}
5,7 is also a pair, why the code has not generated it.?

• Code updated. I was incrementing the variable i more than I need to (in line 24).