Description:
Reverse the elements of an array in place.
Reverse the elements of an array in place.
C Code
#include <stdio.h>
int main() {
int arr[] = {1,2,3,4,5}, n = 5;
for (int i = 0, j = n-1; i < j; i++, j--) {
int t = arr[i]; arr[i] = arr[j]; arr[j] = t;
}
for (int i = 0; i < n; i++) printf("%d ", arr[i]);
return 0;
}
Expected Output
5 4 3 2 1