home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
GLEN
/
MC20.ZIP
/
PRIME.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-20
|
727b
|
29 lines
/*
* Very simple program to find prime numbers.
* Note: 2 is neither tested nor displayed by this program.
*
* Dave dunfield
*/
#include \mc\stdio.h
#define MAXPRIME 1000 /* Search up to here */
/*
* Main (and only) function
*/
main()
{
int num, test, limit;
char flag;
for(num=1; num < MAXPRIME; num += 2) { /* Test range */
limit = num/2; /* Only test to here */
flag = 1; /* Assume prime */
for(test = 2; test <= limit; ++test) { /* Test for factors */
if(!(num%test)) { /* No remainder: factor */
flag = 0; /* Indicate not prime */
break; } } /* Waste no more time */
if(flag) /* Prime number, display */
printf("%d\n", num); }
}