home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l224 / 2.img / TFEXMPL2.ZIP / PRIME0.C next >
Encoding:
Text File  |  1990-10-29  |  725 b   |  36 lines

  1. /* Copyright (c) 1990, Borland International */
  2. /*  Program for generating prime numbers using Euclid's method */
  3.  
  4. int primes[1000];
  5. #define MAXPRIMES 1000
  6.  
  7. main()
  8. {
  9.    int j;
  10.    int lastprime, curprime;
  11.  
  12.    primes[0] = 2;
  13.    primes[1] = 3;
  14.    lastprime = 1;
  15.    curprime  = 3;
  16.  
  17.    printf("prime %d = %d\n", 0, primes[0]);
  18.    printf("prime %d = %d\n", 1, primes[1]);
  19.    while(curprime < MAXPRIMES)
  20.    {
  21.       for(j = 0; j <= lastprime; j++)
  22.      if((curprime % primes[j]) == 0)
  23.      {
  24.         curprime += 2;
  25.  
  26.         break;
  27.      }
  28.       if(j <= lastprime)
  29.      continue;
  30.       lastprime++;
  31.       printf("prime %d = %d\n", lastprime, curprime);
  32.       primes[lastprime] = curprime;
  33.       curprime += 2;
  34.    }
  35. }
  36.