+ 2

Programme to print 10 prime no and their sum ?

c++ programme please

6th Mar 2018, 8:28 AM
Atul Sati
Atul Sati - avatar
2 Respostas
+ 3
#include <iostream> bool prime(int n) { for (int i = 2; i <= n / 2; i++) if ((n%i) == 0)return false; return true; } int main() { int count = 0; int sum = 0; for (int i = 0; true ; i++) { if (prime(i)) { std::cout << i << " | "; sum += i; count++; } if (count == 10) break; } std::cout<<"Sum = "<<sum<<std::endl; return 0; }
6th Mar 2018, 2:39 PM
Eugene Overchenko
Eugene Overchenko - avatar
9th Mar 2018, 10:56 AM
Eugene Overchenko
Eugene Overchenko - avatar