Онлайн компилятор C

#include <stdio.h> int main() { const int N = 10; int A [N],i,j,c; int half=N/2; for (i=0;i<N;i++) {scanf("%d",&A[i]); } for (i=0;i<half;i++){ for (j=0;j<half;j++){ if (A[j]>A[j+1]){ c=A[j]; A[j]=A[j+1]; A[j+1]=c; } } } for (i=half;i<N;i++){ for (j=half;j<N;j++){ if (A[j]>A[j+1]){ c=A[j]; A[j]=A[j+1]; A[j+1]=c; } } } for (i=0;i<N;i++){ printf("%d ",A[i]); } return 0;}
This code reads 10 integers, then sorts the first half (indices 0-4) in ascending order using bubble sort, and separately sorts the second half (indices 5-9) also in ascending order. The two halves are sorted independently, so the whole array is not fully sorted from smallest to largest.

- In the second sorting loop, the inner loop condition `j < N` is correct, but the comparison `A[j] > A[j+1]` will access `A[N]` when `j` is `N-1`, which is out of bounds. Check the loop bounds for the second half to avoid accessing beyond the array.
- The first sorting loop has a similar issue: when `j` is `half-1`, it compares `A[half-1]` with `A[half]`, which is the first element of the second half. This mixes the two halves during sorting. Decide whether you want to keep the halves separate or sort the entire array.