28 lines
373 B
C
28 lines
373 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
static int
|
|
isPrime(int number)
|
|
{
|
|
if (number <= 1)
|
|
return 0;
|
|
for (int i = 2; i * i <= number; i++)
|
|
if (number % i == 0)
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
long sum = 0;
|
|
for(int i = 0; i < 2000000; i++)
|
|
{
|
|
if (isPrime(i))
|
|
{
|
|
sum += i;
|
|
}
|
|
}
|
|
printf("The sum of all the primes below 2,000,000 is %ld\n", sum);
|
|
}
|