By DePaul Dimadis
Choose your prefered Language: greek_flag uk_flag

Two prime numbers are called twins if they differ by 2 (e.g., 3 and 5, 101 and 103). Write a C language program that will find and display all positive twin prime numbers that are less than 10000.

  • TIP-1: To check the results of your program: the last two twins that are less than 10000 are numbers 9929 and 9931.
  • TIP-2: The following programming code snippet finds and displays the positive prime numbers that exist up to a given n (n = unknown) limit.
#include <stdio.h>
int main()
{
      int posprime, posDiv,n;
      do {
            printf("limit=? ( > 0 please) ");
            scanf_s("%d",&n);
      } while (n <= 0);
      printf("Primes < = %5d\n",n);
      for ( posprime = 2;posprime <= n;posprime++ )
     {
          for (posDiv = 2;posDiv < posprime; posDiv++)
                if ( posprime%posDiv == 0) break;
         if (posDiv == posprime)
             printf("%3d ",posprime);
    }
return 0;
}