Can someone explain how the last for loop works which prints out the user's input backwards?? Thanks in advance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 10;
int nums[SIZE];
for(int i=0; i<SIZE; i++)
{
cout << "Please enter a number: ";
cin >> nums[i];
}
// Print the numbers backwards
for(int i=SIZE-1; i>=0; i--)
{
cout << nums[i] << " ";
}
cout << endl;
}
|
Last edited on