A pair of (positive) integer numbers are called twin primes if they are both prime numbers and the difference between them is 2, i.e. they are consecutive odd numbers and they are prime numbers. (3, 5), (5, 7) and (11, 13) are three examples of such pair of twin prime numbers.
Write a program to display all the pairs of twin prime numbers which are less than 100.
Caution: You need to write a program to find and list all the twin primes. If you just list all of the twin prime numbers, you will get 0 credit.
thank you.
I did my best,but the result is far from what should appear. I'd appreciate it if any body can correct my mistake.
#include "stdafx.h"
#include "simpio.h"
#include "genlib.h"
#include "math.h"
int _tmain(int argc, _TCHAR* argv[])
{
int i,j,n;
for (i=3;i<=100;i++)
{
for (j=2;j<=sqrt((double)i)+1;j++);
{
n=i%j;
if (!n==0)
{
printf("%d,%d\n",i,i);
}
}
}
}
---------------------------------------------------------------------------------
I did my best,but the result is far from what should appear. I'd appreciate it if any body can correct my mistake.