Group
Flow Control in C++
Objective
1. Use a for loop to iterate from 1 to 100.
2. In each iteration, print the current number.
3. Test the program to make sure it prints all numbers from 1 to 100.
Print numbers from 1 to 100 using a for loop.
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 1 to 100
for (int i = 1; i <= 100; ++i) {
cout << i << endl; // Print the current value of i
}
return 0; // Return 0 to indicate that the program executed successfully
}
Output
1
2
3
4
5
6
7
8
9
10
...
99
100