+ 2
Programme to print 10 prime no and their sum ?
c++ programme please
2 Answers
+ 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;
}