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

#include <stdio.h> int main() { int A[10]; for (int i = 0; i < 10; i++) { scanf("%d", &A[i]); } int end = 9; int isSort = 0; while (isSort == 0) { isSort = 1; for (int i = 0; i < end; i++) { if (A[i] % 10 > A[i + 1] % 10) { int temp = A[i]; A[i] = A[i + 1]; A[i + 1] = temp; isSort = 0; } } end--; } for (int i=0;i<10;i++){ printf("%d ",A[i]); } return 0; }
This code reads 10 integers into an array, then sorts them using a bubble sort algorithm. The sorting comparison is based on the last digit of each number (using the modulo operator % 10). After sorting, it prints the array.

- The bubble sort uses a variable `end` that decreases each pass, which is correct for standard bubble sort. However, the condition `i < end` means the last element compared in each pass is `A[end-1]` and `A[end]`. Since `end` starts at 9, the first pass compares up to index 8 and 9, which is fine. But after `end--`, the next pass compares up to index 7 and 8, and so on. This is correct for bubble sort.

- The sorting logic compares `A[i] % 10` with `A[i+1] % 10`. This sorts the numbers by their last digit only. For example, 23 and 45: 23%10=3, 45%10=5, so 23 comes before 45. But if two numbers have the same last digit, their relative order is not changed because the swap only happens when the last digit of the left is greater than the right. This is a stable sort by last digit.