Write a function, MAX3, which uses 3 parameters and returns the value of the largest, then test the function in a program | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
- 1

Write a function, MAX3, which uses 3 parameters and returns the value of the largest, then test the function in a program

determine the largest of 3 (c++ program)

15th Dec 2017, 6:34 PM
ROCK&RAUL
ROCK&RAUL - avatar
1 Resposta
+ 8
Here's my idea, as for the explanation of how it's done, you can Google for C ternary operator. #include <iostream> using namespace std; int MAX3(int a, int b, int c) { return (a>b) ? (a>c) ? a : c : (b>c) ? b : c; } int main() { cout << MAX3(1,2,3) << endl; cout << MAX3(1,-5,7) << endl; cout << MAX3(1,21,-5) << endl; return 0; } Hth, cmiiw
15th Dec 2017, 7:31 PM
Ipang