home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
bc45
/
tprofexm.pak
/
PRIME0.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-23
|
799b
|
36 lines
/* Copyright (c) 1990, 1992, Borland International */
/* Program for generating prime numbers using Euclid's method */
#include <stdio.h>
int primes[1000];
#define MAXPRIMES 1000
void main(void)
{
int j;
int lastprime, curprime;
primes[0] = 2;
primes[1] = 3;
lastprime = 1;
curprime = 3;
printf("prime %d = %d\n", 0, primes[0]);
printf("prime %d = %d\n", 1, primes[1]);
while(curprime < MAXPRIMES)
{
for(j = 0; j <= lastprime; j++)
if((curprime % primes[j]) == 0)
{
curprime += 2;
break;
}
if(j <= lastprime)
continue;
lastprime++;
printf("prime %d = %d\n", lastprime, curprime);
primes[lastprime] = curprime;
curprime += 2;
}
}