Write a function called maximum() that accepts three integer
numbers as parameters. The maximum() that returns maximum value
of three arguments that are passed to the function when it is
called. Assume that all three arguments will be of the same data
type.
#include <iostream>
template<typename num>
num maximum(num a, num b, num c) {
if (a > b && a > c) {
return a;
} else if (b > c) {
return b;
} else {
return c;
}
}
int main()
{
int a = 42;
int b = 20;
int c = 12;
float d = 19.07;
float e = 19.09;
float f = 19.01;
double j = 16.0475;
double k = 16.0155;
double l = 16.0622;
std::cout << maximum(a, b, c) << "\n";
std::cout << maximum(d, e, f) << "\n";
std::cout << maximum(j, k, l) << std::endl;
return 0;
}
Comments
Leave a comment