In my program it program the array prints from ascending order, but i'm trying to modify it so it prints in descending order. Could use some help.
#include <iostream>
#include <algorithm>
int main()
{
const int length = 5;
int array[length] = {35, 67, 75, 60, 11};
std::sort(std::begin(array), std::end(array));
for(int i = 0; i < length; i++)
{
std::cout << array[i] << ' ';
}
return 0;
}
std::sort can take 3rd parameter, a comparator, which will say how to order the elements inside the array.
You can pass one of standard comparators inside your call to std::sort
std::sort(std::begin(array), std::end(array), std::greater<int>{});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With