Home / C / c program to check for twin prime numbers

c program to check for twin prime numbers

Here is given c program for Twin Prime numbers.

But before let us see what exactly is a Twin Prime  number ?
A Twin Prime number are those numbers which are prime and having a difference of 2 between the two prime numbers.

Example: 11 and 13.
These numbers are itself prime numbers with a difference of 2 between them i.e d=13-11 which is 2 .Hence the two numbers are twin prime.

#include<Math.h> // include a header file for abs functions for absolute value.
void main()
int i,n1,n2; // here n1 and n2 are the two input numbers
int d; // d is the variable to store the difference of two numbers
int c1=0,c2=0; // c1 and c2 are the counter values for checking the numbers are prime
printf("Enter a Number 1\n");
printf("Enter Number 2\n");
c1++;       // if counter c1 is equal to 2 then the number n1 is prime
c2++;        // if counter c2 is equal to 2 then the number n2  is prime
d=abs(n1-n2);     // here d is difference which calculate the absolute value i.e Modulous of |n1-n2|
if(d==2 && c1==2 && c2==2)
printf("The Two Numbers are Twin Prime\n");
printf("The two Numbers are Not Twin Prime\n");


c program for twin prime
c program to check for twin prime numbers

Check Also

Restrict Mouse Pointer Position C Graphics Program

This C Program will restrict the Mouse Pointer location or to a particular position or x,y ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.