C Program to sort the numbers in descending order

Problem Statement

Write a program in C to sort the given numbers in descending order.


How to sort the number in descending order in C ?

#include <stdio.h> 
int main () 
{ 
   int i,j,a,n=5,number[15]; 
   number[0]=1; 
   number[1]=7; 
   number[2]=8; 
   number[3]=4; 
   number[4]=6; 
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 ("\ndescending order of entered numbers"); 
for (i=0; i<n; ++i) 
printf ("\n%d",number[i]); 
}

Leave Your Comment

Liked this content?. Please spread the word :)