C++ Exercises: Read seven numbers and sorts them in descending order
C++ Basic: Exercise-68 with Solution
Write a C++ program to read seven numbers and sorts them in descending order.
Pictorial Presentation:
Sample Solution:
C++ Code :
#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;
}
Sample Output:
Sample Input 2 5 8 9 7 3 4 sample Output 9 8 7 5 4 3 2
Flowchart:
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C++ program to which prints the central coordinate and the radius of a circumscribed circle of a triangle which is created by three points on the plane surface.
Next: Write a C++ program to read an integer n and prints the factorial of n, assume that n ≤ 10.
What is the difficulty level of this exercise?