在线编译器 C

#include <stdio.h> int main() { int N = 12; int A[12]; for (int i = 0; i < N; i++) { scanf("%d", &A[i]); } for (int i = 0; i < 4 / 3; i++) { int temp = A[i]; A[i] = A[3 - i]; A[3 - i] = temp; } for (int i = 0; i < 4 / 3; i++) { int temp = A[4 + i]; A[4 + i] = A[7 - i]; A[7 - i] = temp; } for (int i = 0; i < 4 / 3; i++) { int temp = A[8 + i]; A[8 + i] = A[11 - i]; A[11 - i] = temp; } for (int i = 0; i < 12; i++) { printf("%d ", A[i]); } return 0; }
This code reads 12 integers into an array, then performs three separate reversal operations on blocks of 4 elements each (indices 0-3, 4-7, 8-11). Finally it prints the array.

- The loop condition `i < 4 / 3` uses integer division, so `4 / 3` equals 1. This means each reversal loop runs only once, swapping just the first and last element of each block (indices 0 and 3, 4 and 7, 8 and 11). The middle elements (indices 1 and 2, 5 and 6, 9 and 10) are never swapped. Think about what loop condition would correctly reverse all elements in each block of 4.