#include <iostream> using namespace std; int main() { int n = 30; int sum = 0; while (n <= 70) { if (n % 4 == 0) sum = sum + n; n++; } cout << "Sum = " << sum << endl; system("pause"); return 0; }
//2) DO WHILE #include <iostream> using namespace std; int main() { int n = 30; int sum = 0; do { if (n % 4 == 0) sum = sum + n; n++; } while (n <= 70); cout << "Sum = " << sum << endl; system("pause"); return 0; }
Answers & Comments
#include <iostream>
using namespace std;
int main() {
int n = 30;
int sum = 0;
while (n <= 70) {
if (n % 4 == 0) sum = sum + n;
n++;
}
cout << "Sum = " << sum << endl;
system("pause");
return 0;
}
//2) DO WHILE
#include <iostream>
using namespace std;
int main() {
int n = 30;
int sum = 0;
do {
if (n % 4 == 0) sum = sum + n;
n++;
} while (n <= 70);
cout << "Sum = " << sum << endl;
system("pause");
return 0;
}