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 33 34 35 36

#include <iostream>
#include <algorithm>
using namespace std;
int medianOf( int n1, int n2, int n3, int n4, int n5 )
{
if ( n1 > n2 ) std::swap(n1, n2) ;
if ( n2 > n3 ) std::swap(n2, n3) ;
if ( n3 > n4 ) std::swap(n3, n4) ;
if ( n4 > n5 ) std::swap(n4, n5) ;
// n5 is now the largest value of the 5.
if ( n1 > n2 ) std::swap(n1, n2) ;
if ( n2 > n3 ) std::swap(n2, n3) ;
if ( n3 > n4 ) std::swap(n3, n4) ;
// n4 is the second largest value of the 5.
if ( n1 > n2 ) std::swap(n1, n2) ;
if ( n2 > n3 ) std::swap(n2, n3) ;
// n3 is the third largest value of the 5.
// we can stop here, because the third largest value is the median.
return n3 ;
}
int main()
{
float n1, n2, n3, n4, n5 ;
std::cout << "Please enter five numbers: " ;
std::cin >> n1 >> n2 >> n3 >> n4 >> n5 ;
std::cout << "median is " << medianOf(n1, n2, n3, n4, n5) ;
}
 