C Program to sort numbers in ascending order

Problem Statement

You need to write a program in C to sort the given numbers in ascending order.

How to sort numbers in ascending order in C ?

#include <stdio.h>
int main ()
{
   int i,j,a,n=5,number[15];
   number[0]=7;
   number[1]=4;
   number[2]=9;
   number[3]=2;
   number[4]=11;
for (i=0; i<n; ++i)
{
   for (j=i+1; j<n; ++j)
   {
     if (number[i] > number[j])
     {
       a= number[i];
       number[i] = number[j];
       number[j] = a;
     }
   }
}
printf ("\nAscending order of the numbers");
for (i=0; i<n; ++i)
printf ("\n%d",number[i]);
}

Leave Your Comment