#include <stdio.h>
int main() {
int N = 10;
int A[10];
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
for (int i = 0; i < 5 / 2; i++) {
int temp = A[i];
A[i] = A[4 - i];
A[4 - i] = temp;
}
for (int i = 0; i < 5 / 2; i++) {
int temp = A[5+i];
A[i] = A[9 - i];
A[9 - i ] = temp;
}
for (int i = 0; i < 10; i++){
printf("%d ", A[i]);
}
return 0;
}
This code reads 10 integers into an array, then attempts to reverse two halves of the array separately, but the logic for the second half is incorrect. The first loop correctly reverses the first 5 elements (indices 0 to 4), but the second loop mistakenly uses `A[i]` instead of `A[5+i]` on the left side of the swap, which corrupts the first half again.
- In the second reversal loop, check which array index you are assigning to on the left side of the swap. You want to swap elements within the second half (indices 5 to 9), but you are writing to `A[i]` which is in the first half.
- The loop condition `i < 5 / 2` is correct for reversing 5 elements, but integer division means `5/2` equals 2, so only 2 swaps are performed. Think about whether 2 swaps are enough to reverse 5 elements.