โ Back to Arrays
Question 101
Print in Reverse Order
Print in Reverse Order
An array called nums has already been created for you with the values {10, 20, 30, 40, 50}.
Your task is to print all elements in reverse order, each on its own line. That means the last element prints first, and the first element prints last.
To do this, you need a for loop that starts at the last index (4) and counts down to 0. The loop should look like:
for (int i = 4; i >= 0; i--)
The key difference from a normal loop is that i starts high and decreases with i-- instead of i++.
Expected output:
50
40
30
20
10Expected Output:
50 40 30 20 10
Topics:
Arrays
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.