fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. array<int, 10> arr;
  6. int c;
  7. for (int & i : arr) cin >> i;
  8. cout<< "1 - If you wish to find the average of the integers, press 1 \n";
  9. cout<< "2 - If you wish to find the largest integer, press 2 \n";
  10. cout<< "3 - If you wish to find the smallest integer, press 3 \n";
  11. cout<< "4 - If you wish to find the median number, press 4 \n";
  12. cout<< "5 - If you wish to sort the integers in ascending order, press 5 \n";
  13. cout<< "6 - If you wish to sort the integers in descending order, press 6 \n";
  14. cin >> c;
  15. switch (c) {
  16. case 1:
  17. cout << "The average of the numbers is " << accumulate(arr.begin(), arr.end(), 0) / arr.size() << endl;
  18. break;
  19. case 2:
  20. cout << "The largest integer is " << *max_element(arr.begin(), arr.end()) << endl;
  21. break;
  22. case 3:
  23. cout << "The smallest integer is " << *min_element(arr.begin(), arr.end()) << endl;
  24. break;
  25. case 4:
  26. nth_element(arr.begin(), arr.begin() + arr.size() / 2, arr.end());
  27. cout << "The median number is " << arr[arr.size() / 2] << endl;
  28. break;
  29. case 5:
  30. sort(arr.begin(), arr.end());
  31. for (int i : arr) cout << i << " ";
  32. cout << endl;
  33. break;
  34. case 6:
  35. sort(arr.begin(), arr.end(), greater<int>());
  36. for (int i : arr) cout << i << " ";
  37. cout << endl;
  38. break;
  39. default:
  40. cerr << "Invaid choice\n";
  41. return 1;
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0s 3104KB
stdin
2 4 6 8 10 9 7 5 3 1
1
stdout
1 - If you wish to find the average of the integers, press 1 
2 - If you wish to find the largest integer, press 2 
3 - If you wish to find the smallest integer, press 3 
4 - If you wish to find the median number, press 4 
5 - If you wish to sort the integers in ascending order, press 5 
6 - If you wish to sort the integers in descending order, press 6 
The average of the numbers is 5