#include <stdio.h>
void reverse_array(int arr[], int n) {
// Your logic here
int i, hold;
for (i=0; i < (n/2); i++ ) {
hold= arr[i];
arr[i]= arr[n-i-1];
arr[n-i-1]= hold;
}
}
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;
}
Solving Approach
use a variable to hold value of a cell at the top while you swap it with corresponding cell in bottom
even sized lists are straightforward
odd sized lists smple: nothing happens to the middle element