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 2, to check for the next number.

Related Reading:


Leave a Comment

%d bloggers like this: