// A C program to print sum of all prime numbers between 1 to N
#include<stdio.h>#include<conio.h>
void main()
{
clrscr();
int count, N, i,Prime, pSum=0;
printf("Enter a Number\n");
scanf("%d", &N);
for(count = 2; count <= N; count++)
{
Prime = 1;
for(i = 2; i <=(count/2); ++i)
{
if(count%i==0)
{
Prime = 0;
break;
}
}
if(Prime==1)
pSum+=count;
}
printf("Sum of Prime Numbers between 1 to %d : %d", N,pSum);
getch();
}
Output:
0 Comments