add_prime_sum

Subject

Assignment name  : add_prime_sum
Expected files   : add_prime_sum.c
Allowed functions: write, exit
--------------------------------------------------------------------------------

Write a program that takes a positive integer as argument and displays the sum
of all prime numbers inferior or equal to it followed by a newline.

If the number of arguments is not 1, or the argument is not a positive number,
just display 0 followed by a newline.

Yes, the examples are right.

Examples:

$>./add_prime_sum 5
10
$>./add_prime_sum 7 | cat -e
17$
$>./add_prime_sum | cat -e
0$
$>

Commented solution

There's actually nothing really complicated in the fact of making a simple addition between some numbers, the real challenge is to build the supportive function, hope you remember how to build an atoi function.

add_prime_sum.c

Last updated

Was this helpful?