Write a function template named maximum() that returns the maximum value of three arguments that are passed to function when it is called. Assume that all three arguments will be of the same data type.
#include<iostream>
using namespace std;
template <typename P>
P maximum(P first, P second, P third){
P max = first;
if(second>first && second > third){
max = second;
}
else if(third > first && third > second){
max = third;
}
return max;
}
int main(){
cout<<maximum(8,2,20)<<endl; //Testing integer values
cout<<maximum(1.90892,0.76454,0.20)<<endl; //Testing float values
cout<<maximum('C','D','A')<<endl; //Testing character values
}
Comments
Thank you so much
Leave a comment