c++ programming
Write only the do while loop statements to print the following sequences.
1) 28 21 15 10 6 3 1 0
2) 12 11 9 6 2 -3
#include <iostream>
using namespace std;
int main() {
int x, dx;
// 1
x = 36;
dx = 8;
do {
x -= dx;
cout << x << " ";
} while (--dx > 0);
cout << endl;
// 2
x = 12;
dx = 0;
do {
x -= dx++;
cout << x << " ";
} while (x > 0);
cout << endl;
}
Comments
Leave a comment