# Answer to Question #22722 in C++ for EMMANUEL

Question #22722

write a program using c++ to find the sum of 1st 10 prime numbers.

Expert's answer

#include<iostream>

using namespace std;

int isprime(int valuex){

int x,j;

x=1;

for (j=2 ; j<valuex; j++)

{ if ((valuex%j)==0) x=0; }

if(x!=0) return 1;

& else return 0;

}

int count = 0, sum = 0, i = 1;

void main(){

while (count<11){

if (isprime(i)){

cout<<i<<"\n";

count++;

sum+=i;

}

i++;

}

cout<<"The sum of 1st 10 prime numbers is "<<sum<<"\n";

system("pause");

}

using namespace std;

int isprime(int valuex){

int x,j;

x=1;

for (j=2 ; j<valuex; j++)

{ if ((valuex%j)==0) x=0; }

if(x!=0) return 1;

& else return 0;

}

int count = 0, sum = 0, i = 1;

void main(){

while (count<11){

if (isprime(i)){

cout<<i<<"\n";

count++;

sum+=i;

}

i++;

}

cout<<"The sum of 1st 10 prime numbers is "<<sum<<"\n";

system("pause");

}

## Comments

## Leave a comment