I have to find the sum of the prime numbers below 2million so here is the program that i have written.
#include <iostream>
using namespace std;
bool is_prime(int);
int total=0;
int main()
{
int num=2000000;
for(int x=1;x<=(num);x++)
{
if(is_prime(x)==true)
{
total+=x;
cout<< total<<"\n";
}
}
cout<< total;
return 0;
}
bool is_prime(int y)
{
for(int a=1;a<=(y/2);a++)
{
if(y%a==0)
{
return false;
}
}
return true;
}
I dont know but it gives me 1 as the answer.