Problem :
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Find the sum of all the primes below two million.
Solution :
#include<stdio.h> #include<math.h> int main() { long long int num,i,j,sum=0; printf("Enter any number:"); scanf("%lld",&num); for(j=2;j<num;j++) { for(i=2;i<=sqrt(j)&&j%i!=0;i++); if(i>sqrt(j)) sum=sum+j; } printf("Sum=%lld",sum); return 0; }
No comments:
Post a Comment