Calculate a PRIME number LIST using C language
This C program calculates a list with first prime numbers.
Build the program
C is a compiled language, so we will need to install a C compiler: gcc
$ sudo aptitude install gccWe copy this text in a file, e.g: prime_calculator.c
Next we compile the file:
$ gcc -o prime_calculator -lm prime_calculator.c -Wallor if we want further optimization:
$ gcc -o prime_calculator -lm prime_calculator.c -Wall -O3-lm option links the math library so we can calculate square roots.
Execute the program
After compilation, an executable appears: prime_calculator.
$ chmod a+x prime_calculator # we grant it execution permission.If we want to show first ten prime numbers:
$ ./prime_calculator 10PRIME LIST:
2 3 5 7 11 13 17 19 23 29
If we pass more than two arguments, it calculates the prime list but does not show anything. Just to measure its execution time:
$ time ./prime_calculator 10 *real 0m0.008s
user 0m0.004s
sys 0m0.000s