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 37 38 39 40 41 42 43 44 45 46 47 48
|
//Program consisting of three functions that finds the middle number.
#include <iostream>
#include <algorithm>
using namespace std;
int max3 (int, int, int);// prototype
int min3 (int, int, int); //prototype
int middle (int, int, int); //prototype
void main ()
{
int a;
int b;
int c;
int mx;
int mn;
int md;
cout << "Enter a value for a." << endl;
cin >> a;
cout << "Enter a value for b." << endl;
cin >> b;
cout << "Enter a value for c." << endl;
cin >> c;
mx = max3 (a,b,c);
mn = min3 (a, b, c);
md = middle (a,b,c); //a,b,c are arguments.
cout << "Middle number = " << md << endl;
}
//function definition
int max3 (int a, int b, int c) // int a, b, and c are parameters.
{
return max (a, max (b,c));
}
//function definition
int min3 (int a, int b, int c)
{
return min (a, min (b,c));
}
//function definition
int middle (int a, int b, int c) // int a, b, and c are parameters.
{
return (a + b + c) - (max (a, max (b,c)) + min (a, min (b,c)));
}
|