Reverse an Array

Lab C Beginner 10 points

Read n integers (≤ 100) into an array and print them in reverse order.

Input

Line 1: n. Line 2: n integers.

Output

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

Declare a fixed-size array big enough for the maximum n.

Indexes run from 0 to n-1.

Solution explanation

C arrays have a fixed size and no bounds checking - staying inside them is your job.

Show solution
#include <stdio.h>

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