Google News
logo
C Program to Arrange Numbers in Ascending Order
* In 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.
Program :
#include <stdio.h>

void sort_numbers_ascending(int number[], int count)
{
   int temp, i, 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 (i = 0; i < count; ++i)
      printf("%d\n", number[i]);
}
void main()
{
   int i, count, number[20];
 
   printf("How many numbers you are enter:");
   scanf("%d", &count);
   printf("\nEnter the numbers one by one:");
   
   for (i = 0; i < count; ++i)
      scanf("%d", &number[i]);
 
   sort_numbers_ascending(number, count);
}
Output :
How many numbers you are enter:5
Enter the numbers one by one:14
22
5
9
11
Numbers in ascending order:
5
9
11
14
22