- #include "stdio.h"
-
#include <math.h>
-
-
int is_prime(int n)
-
{
-
int i = 3;
-
if (n!=2&&!(n&1)) return 0; /* even num filter out except 2 */
-
while (i <= sqrt(n))
-
{
-
if (n%i==0)
-
return 0;
-
i+=2;
-
}
-
return 1;
-
}
-
-
-
void main()
-
{
-
const int MAX=1000;
-
int num=2,i=0;
-
while(num<MAX)
-
{
-
if (is_prime(num))
-
printf("%03d%s", num, ++i%10?" ":"\n");
-
num ++;
-
}
-
printf("\n");
- }
- #Makefile
-
-
- CC := gcc
-
- default: test.o
- $(CC) -lm test.c -o test