#include <bits/stdc++.h>
using namespace std;
int main( ) {
array< int , 10 > arr;
int c;
for ( int & i : arr) cin >> i;
cout << "1 - If you wish to find the average of the integers, press 1 \n " ;
cout << "2 - If you wish to find the largest integer, press 2 \n " ;
cout << "3 - If you wish to find the smallest integer, press 3 \n " ;
cout << "4 - If you wish to find the median number, press 4 \n " ;
cout << "5 - If you wish to sort the integers in ascending order, press 5 \n " ;
cout << "6 - If you wish to sort the integers in descending order, press 6 \n " ;
cin >> c;
switch ( c) {
case 1 :
cout << "The average of the numbers is " << accumulate( arr.begin ( ) , arr.end ( ) , 0 ) / arr.size ( ) << endl;
break ;
case 2 :
cout << "The largest integer is " << * max_element( arr.begin ( ) , arr.end ( ) ) << endl;
break ;
case 3 :
cout << "The smallest integer is " << * min_element( arr.begin ( ) , arr.end ( ) ) << endl;
break ;
case 4 :
nth_element( arr.begin ( ) , arr.begin ( ) + arr.size ( ) / 2 , arr.end ( ) ) ;
cout << "The median number is " << arr[ arr.size ( ) / 2 ] << endl;
break ;
case 5 :
sort( arr.begin ( ) , arr.end ( ) ) ;
for ( int i : arr) cout << i << " " ;
cout << endl;
break ;
case 6 :
sort( arr.begin ( ) , arr.end ( ) , greater< int > ( ) ) ;
for ( int i : arr) cout << i << " " ;
cout << endl;
break ;
default :
cerr << "Invaid choice\n " ;
return 1 ;
}
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWFycmF5PGludCwgMTA+IGFycjsKCWludCBjOwoJZm9yIChpbnQgJiBpIDogYXJyKSBjaW4gPj4gaTsKCWNvdXQ8PCAiMSAtIElmIHlvdSB3aXNoIHRvIGZpbmQgdGhlIGF2ZXJhZ2Ugb2YgdGhlIGludGVnZXJzLCBwcmVzcyAxIFxuIjsKCWNvdXQ8PCAiMiAtIElmIHlvdSB3aXNoIHRvIGZpbmQgdGhlIGxhcmdlc3QgaW50ZWdlciwgcHJlc3M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GVuZGw7CgkJYnJlYWs7CgljYXNlIDU6CgkJc29ydChhcnIuYmVnaW4oKSwgYXJyLmVuZCgpKTsKCQlmb3IgKGludCBpIDogYXJyKSBjb3V0IDw8IGkgPDwgIiAiOwoJCWNvdXQgPDwgZW5kbDsKCQlicmVhazsKCWNhc2UgNjoKCQlzb3J0KGFyci5iZWdpbigpLCBhcnIuZW5kKCksIGdyZWF0ZXI8aW50PigpKTsKCQlmb3IgKGludCBpIDogYXJyKSBjb3V0IDw8IGkgPDwgIiAiOwoJCWNvdXQgPDwgZW5kbDsKCQlicmVhazsKCWRlZmF1bHQ6CgkJY2VyciA8PCAiSW52YWlkIGNob2ljZVxuIjsKCQlyZXR1cm4gMTsKCX0KCXJldHVybiAwOwp9
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