#include <stdio.h>
void reverse_array(int *ptr, int n) {
// Your logic here
int *left = ptr, *right = ptr + n-1;
while(left < right){
int temp =*left;
*left = *right;
*right = temp;
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;
}Use left and right pointers pointing to the first and last element of the array, and keep swapping till you converge in the center.
Input
5 1 2 3 4 5
Expected Output
5 4 3 2 1