#include <stdio.h>
int main (int argc,char *argv[]) {
int i,j,sum = 0,range = 1000;
int flag = 0,count = 0;
for (i = 2 ;count < 1000;i++) {
//check for prime
for (j = 2; j < i ;j++) {
if (i % j == 0) {
flag = 1;break;
}
}
if (flag == 0) {
sum = sum + i;
count++;
}
flag = 0;
}
printf("Sum of First 1000 Prime numbers = %d\n",sum);
return 0;
}
Output -
Sum of First 1000 Prime numbers = 3682913
int main (int argc,char *argv[]) {
int i,j,sum = 0,range = 1000;
int flag = 0,count = 0;
for (i = 2 ;count < 1000;i++) {
//check for prime
for (j = 2; j < i ;j++) {
if (i % j == 0) {
flag = 1;break;
}
}
if (flag == 0) {
sum = sum + i;
count++;
}
flag = 0;
}
printf("Sum of First 1000 Prime numbers = %d\n",sum);
return 0;
}
Output -
Sum of First 1000 Prime numbers = 3682913
Comments