/* max-of-two.cpp program to demonstrate a value-returning function */ #include using namespace std; //function prototypes int maxOfTwo(int m, int n); int main(){ int n1, n2; // user inputs //prompt and read cout << "enter m, n: "; cin >> n1 >> n2; // function call cout << "max of " << n1 << ' ' << n2 << " = " << maxOfTwo(n1, n2) << endl; return 0; } /* maxOfTwo() ------------------------------------------------ returns max of n1, n2 */ int maxOfTwo(int m, int n){ int max; if(m > n) max = m; else max = n; return max; } /* alternate version: no local variable, two return statements int maxOfTwo(int m, int n){ if(m > n) return m; else return n; } */ /* alterate version: use ?: operator for a one-line function int maxOfTwo(int m, int n){ return ((m > n)? m : n) ; } */