Q:

Write a C++ program to read seven numbers and sorts them in descending order

0

Write a C++ program to read seven numbers and sorts them in descending order.

Sample Output:

Sample Input 
2 5 8 9 7 3 4 
sample Output
 9 8 7 5 4 3 2

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

int main() {
    int num[7];
    for (int i = 0; i != 7; ++i) {
        cin >> num[i];
    }
    sort(num, num+7);
    cout << " " << num[6]  << " " << num[5]  << " " << num[4]  << " " << num[3]  << " " << num[2] << " " << num[1] << " " << num[0];
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now