#include <stdio.h> inline void swap(int* x, int* y) { int temp = *x; *x = *y; *y = temp; } void reverse_array(int arr[], int n) { // Your logic here int left = 0; int right = n-1; while (left < right) { swap(&arr[left], &arr[right]); left++; right--; } } int main() { int n; scanf("%d", &n); int arr[100]; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } reverse_array(arr, n); for (int i = 0; i < n; i++) { printf("%d", arr[i]); if(i < n-1){ printf(" "); } } return 0; }
Test Cases
Test Results
Input
5 1 2 3 4 5
Expected Output
5 4 3 2 1