2011-07-05T09:21:19-04:00
Write a program to print the sum of all prime numbers between 1 and 100 using while loop and do while.
1
2011-07-13T11:05:49-0400
#include <iostream> #include <cstring> using namespace std; int main() { bool prime[101]; memset (prime, true, sizeof(prime)); int i = 2; do { & int n = 2; & while (i * n <= 100) { & prime[i*n] = false; & ++n; & } & ++i; } while (i <= 100); i = 1; int sum = 0; while (i <= 100) { & if (prime[i]) & sum += i; & ++i; } cout << "The sum is " << sum << endl; return 0; }
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 !
Learn more about our help with Assignments:
C++
Comments