Coders Packet

C++ Program to Sort Elements of Array in Descending Order

By Ashish Kumar Gupta

This is a C++ Program to Sort Elements of an Array in Descending Order with the help of the sort() function, we are going to solve this problem

Given a Array of Element Array of Element 3,6,2,4,5 we have to sort this array into descending array 

Algorithm Explanation:

1. first we took an array of five-element.

 

2.  creating a variable "n" to store the size of the array

 

3.the sort() function takes a third parameter “greater()” function to sort in descending order. This function makes a comparison in a way that puts greater elements before.

 

4. after sorting we simply print the element with  the help of a loop 

INPUT:

3,6,2,4,5

OUTPUT:

6,5,4,3,2

 

Download Complete Code

Comments

No comments yet