Read the input sequence into an array. Then, print the elements of the array in reverse order.
Algorithm implementation
Declare an array to store the input sequence.
int m[101];Read the input data.
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &m[i]);Print the elements of the array in a single line in reverse order.
for (i = n - 1; i >= 0; i--)
printf("%d ", m[i]);
printf("\n");Algorithm implementation — STL
Declare a vector to store the input sequence.
vector<int> v;Read the input data.
scanf("%d", &n);
v.resize(n);
for (i = 0; i < n; i++)
scanf("%d", &v[i]);Invert the order of the elements in the array.
reverse(v.begin(), v.end());Print the elements of the array in a single line in reverse order.
for (i = 0; i < n; i++)
printf("%d ", v[i]);
printf("\n");Python implementation
Read the input data.
n = int(input())
v = [int(input()) for _ in range(n)]Invert the order of the elements in the array.
v.reverse()Print the elements of the array in a single line in reverse order.
print(*v)