Skip to main content

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 Nprime
22
33
107
10097
1000997
100009973
10000099991