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

  1. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!