/************************************************/
/*
*/
/*
Prime Number Generator #1
*/
/*
*/
/************************************************/
/* Check for prime number by raw number */
/* crunching. Try dividing all numbers */
/* up to half the size of a given i, if */
/* remainder == 0 then not prime! */
#include
<stdio.h>
#define
MAXINT 500
#define
TRUE 1
#define
FALSE 0
/*************************************************/
/*
Level 0
*/
/*************************************************/
main
()
{
int i;
for
(i = 2; i <= MAXINT; i++)
{
if (prime(i))
{
printf ("%5d",i);
}
}
}
/*************************************************/
/*
Level 1
*/
/*************************************************/
prime
(i) /* check for a prime number
*/
int
i;
{
int j;
for
(j = 2; j <= i/2; j++)
{
if (i % j == 0)
{
return FALSE;
}
}
return
TRUE;
}
0 comments:
Post a Comment