Challenge: Reverse the List

Lab C Beginner 10 points

Read n, then n whole numbers. Print them in reverse order, separated by spaces.

Input

n (1 ≤ n ≤ 100), then n integers.

Output

The numbers in reverse order on one line.

Example

Input

5
1 2 3 4 5

Output

5 4 3 2 1
Sample input available Sample output available
Editor
C

Hints

Store the numbers in an array first.

Then loop from index n - 1 down to 0.

Solution explanation

Once all numbers are stored, a loop that counts down visits them from last to first.

Show solution
#include <stdio.h>

int main() {
    int n;
    int nums[100];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &nums[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
        printf("%d", nums[i]);
        if (i > 0) {
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD