- 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)
2 Respostas
+ 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