Question: Write a program to print the sum of first n prime numbers. Accept the limit 'n' from the user Not sure if im doing right
- Write a program to print the sum of first n prime numbers. Accept the limit 'n' from the user
Not sure if im doing right of the code just let me know where is the mistake...
#include
using namespace std;
int main()
{
int n, i, j, Prime;
bool prime;
cout<< "Enter the sum of first n prime numbers:";
cin>> n;
for(i = 2; i <= n; i++)
{
Prime = 0;
for(j = 2; j <= i/2; j++)
{
if(i % j == 0)
{
Prime = 1;
break;
}
}
if(Prime==0 && n! =1)
cout << i << " ";
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
