/* * twin.c - find the first two twin prime pairs greater than 1000. * * Algorithm: Start with 1001, go up by twos; for each prime number, check * isprime(i+2). */ #include int main() { int i, nleft; extern int isprime(int p); nleft = 2; for (i = 1001; nleft > 0; i += 2) { if (isprime(i) && isprime(i+2)) { printf("%d %d\n", i, i + 2); nleft = nleft - 1; } /* * we needn't worry that in the next loop iteration, we'll print an * overlapping twin prime... because that would constitute a triplet * and the only one of these is 3,5,7, which is <1000. */ } return 0; }