Array In Descending Order

Introduction
  • It is often necessary to arrange the elements in an array in the numerical order i.e. from the highest value to the lowest value 
Software Requirements
  • Turbo C++ OR C. 
Programming
  1. ** ** ** ** ** ** ** ** ** ** * Array in descending order ** ** ** ** ** ** *   
  2. #include < stdio.h > void main()  
  3. {  
  4.     int number[30];  
  5.     int i, j, a, n;  
  6.     printf("Enter the value of N\n");  
  7.     scanf("%d", & n);  
  8.     printf("Enter the numbers \n");  
  9.     for (i = 0; i < n; ++i) scanf("%d", & number[i]);  
  10.     for (i = 0; i < n; ++i) {  
  11.         for (j = i + 1; j < n; ++j)  
  12.         {  
  13.             if (number[i] < number[j])  
  14.             {  
  15.                 a = number[i];  
  16.                 number[i] = number[j];  
  17.                 number[j] = a;  
  18.             }  
  19.         }  
  20.     }  
  21.     printf("The numbers arranged in descending order are given below\n");  
  22.     for (i = 0; i < n; ++i)  
  23.     {  
  24.         printf("%d\n", number[i]);  
  25.     }  
  26. }  
programming 
programming

Explanation
  • In the programming, given above, I have clearly explained how to arrange the numbers in a descending order.
Output

Output
 
Conclusion
  • Thus, the array in the descending order is printed and executed successfully.
Next Recommended Reading Print Alternate Elements In An Array