Group
Flow Control in C++
Objective
1. Use a loop to iterate from 10 to 1.
2. In each iteration, print the current number.
3. Test the program to ensure that the numbers are printed in reverse order from 10 down to 1.
Write a program that prints the numbers from 1 to 10 in reverse order.
Example C++ Exercise
Show C++ Code
#include <iostream> // Include the iostream library for input and output
using namespace std; // Use the standard namespace
// Main function - the entry point of the program
int main() {
// Use a for loop to iterate from 10 to 1
for (int i = 10; i >= 1; --i) {
cout << i << endl; // Print the current value of i (the number)
}
return 0; // Return 0 to indicate that the program executed successfully
}
Output
10
9
8
7
6
5
4
3
2
1