C Program to sort the numbers in descending order


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

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