Answer to Question #22722 in C++ for EMMANUEL

Question #22722
write a program using c++ to find the sum of 1st 10 prime numbers.
1
Expert's answer
2013-01-24T09:12:04-0500
#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");
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS