Write Program
Write
In C, Sieve of Eratosthenes can be written as
c/src/prime.c
loading...
Build for Test
Build C program to executable file main.exe
.
gcc
is used here to build for test.
build with optimization level O3
gcc src/main.c src/prime.c -O3 -o main
gcc command line options can be found at 3 GCC Command Options.
Run and Test
After building C program, test the code with
invoke and test prime function
main.exe 100000
This should shows
output
given number = 100000
max prime = 99991
duration [ms] = 33.996600
The following table shows the calculated prime for given "N".
given N | prime |
---|---|
2 | 2 |
3 | 3 |
10 | 7 |
100 | 97 |
1000 | 997 |
10000 | 9973 |
100000 | 99991 |