C Programming Code Examples C > Sorting Searching Code Examples Program to arrange numbers in ascending order Program to arrange numbers in ascending order The following program prompts user for the n numbers, once the user is done entering those numbers, this program sorts and displays them in ascending order. Here we have created a user defined function sort_numbers_ascending() for the sorting purpose. #include <stdio.h> void sort_numbers_ascending(int number[], int count) { int temp, x, j, k; for (j = 0; j < count; ++j) { for (k = j + 1; k < count; ++k) { if (number[j] > number[k]) { temp = number[j]; number[j] = number[k]; number[k] = temp; } } } printf("Numbers in ascending order:\n"); for (x = 0; x < count; ++x) printf("%d\n", number[x]); } void main() { int x, count, number[20]; printf("How many numbers you are gonna enter:"); scanf("%d", &count); printf("\nEnter the numbers one by one:"); for (x = 0; x < count; ++x) scanf("%d", &number[x]); sort_numbers_ascending(number, count); }