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

#include <stdio.h> int main() { int n; scanf("%d", &n); int num[100], ni = 0; while (n > 0) { num[ni] = n % 10; ni++; n = n / 10; } int temp; int is_sort = 0; while (!is_sort) { is_sort = 1; for (int i = 0; i < ni - 1; i++) { if (num[i] > num[i + 1]) { temp = num[i]; num[i] = num[i + 1]; num[i + 1] = temp; is_sort = 0; } } } for (int i = 0; i < ni; i++) { printf("%d", num[i]); } return 0; }
This code reads an integer, extracts its digits into an array in reverse order, sorts the array in ascending order using bubble sort, and then prints the sorted digits. The output will be the digits of the original number sorted from smallest to largest.

- The digits are stored in reverse order because the loop extracts the last digit first. After sorting, the smallest digit will be printed first, which may produce a number with leading zeros if the original number had zeros.
- Consider what happens when the input number is 0. The while loop condition `n > 0` will be false immediately, so `ni` remains 0, and the program will print nothing. Think about how to handle this case.