1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
#include <utility> // for std::swap
int main()
{
int a, b, c, d, e ;
std::cin >> a >> b ;
if( a > b ) std::swap(a,b) ; // post-condition a <= b
// note: std::swap(a,b) ; may be written as { int temp = a ; a = b ; b = temp ; }
std::cin >> c ;
if( b > c ) std::swap(b,c) ; // post-condition b <= c
if( a > b ) std::swap(a,b) ; // post-condition a <= b, b <= c
std::cin >> d ;
if( c > d ) std::swap(c,d) ; // post-condition c <= d
if( b > c ) std::swap(b,c) ; // post-condition b <= c, c <= d
if( a > b ) std::swap(a,b) ; // post-condition a <= b, b <= c, c <= d
std::cin >> e ;
if( d > e ) std::swap(d,e) ; // post-condition d <= e
if( c > d ) std::swap(c,d) ; // post-condition c <= d, d <= e
if( b > c ) std::swap(b,c) ; // post-condition b <= c, c <= d, d <= e
if( a > b ) std::swap(a,b) ; // post-condition a <= b, b <= c, c <= d, d <= e
std::cout << "numbers: " << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << '\n'
<< " min: " << a << '\n'
<< " max: " << e << '\n'
<< " median: " << c << '\n'
<< "average: " << (a+b+c+d+e) / 5.0 << '\n' ;
}
|