C Program to find the sum of prime numbers between 1 to 1000
//This code is written by Souvik Ghosh
#include <stdio.h>
int primeChecker(int num)
{
int flag = 0;
if (num == 1 || num == 0)
{
return flag = 1;
}
else
{
for (int i = 2; i < num; i++)
{
if (num % i == 0)
{
flag = 1;
}
}
}
return flag;
}
void main()
{
int sum = 0;
for (int i = 1; i <= 1000; i++)
{
if (primeChecker(i) == 0)
{
sum += i;
}
}
printf("Sum of the prime numbers betweeen 1 to 1000 is %d\n", sum);
}
/*
1 is neither prime nor composite because prime number has two positive factors but one has only one positive factor
i.e. 1 itself and it is not composite because composite number has more than two positive factors but 1 has only one
positive factor.
*/