C Program to sort numbers in ascending order


This content was proof-read by Grammarly. You can Try Grammary for FREE

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]); 
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: