how to print sum of prime numbers between 1 to n…using basic method?
Sum of prime numbers
@ynikhil1999
hey nikhil
this code will give you tle on submission but it will work.#include
using namespace std;
int main()
{
int check,n=0,c=0;
cout<<"Enter Prime Number you want to Find: ";
cin>>n;
for(int i=2;i<=1000;i++)
{
check=0;
for(int j=2;j<=i/2;j++)
{
if(i%j==0)
{
check=1;
break;
}
}
if(check==0)
c++;
if(c==n)
{
cout<<n <<" Prime Number is: " <<i;
break;
}
}
return 0;
}
for further optimisation there is a video in the course content sieve of erathothenes watch for better understanding
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.