### 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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include<stdio.h> #include<conio.h> #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=,c2=; // c1 and c2 are the counter values for checking the numbers are prime clrscr(); printf("Enter a Number 1\n"); scanf("%d",&n1); printf("Enter Number 2\n"); scanf("%d",&n2); for(i=1;i<=n1;i++) { if(n1%i==) c1++; // if counter c1 is equal to 2 then the number n1 is prime } for(i=1;i<=n2;i++) { if(n2%i==) 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"); else printf("The two Numbers are Not Twin Prime\n"); getch(); } |

** OUTPUT:**