Title description
Write a program to find the maximum value of 2 integers, 3 integers, and 4 integers respectively. Requires the use of overloaded functions to complete.
Input description
Input 4 integers
Output description
Three results:
the maximum value
of the first two numbers, the maximum value of the last three numbers, and the maximum value of the
four numbers.
Input example
56 78 23 1
Output example
The maximum value of the first two numbers is :
The maximum value of the three numbers after 78 is: 78
The maximum value of the four numbers is: 78 (Chinese colon)
#include <iostream>
using namespace std;
int max(int x,int y,int z,int k)
{
(((x>y)?x:x=y)>z?x:x=z)>k?x:x=k;
return x ;
}
int max(int x,int y,int z)
{
((x>y)?x:x=y)>z?x:x=z;
return x;
}
int max(int x,int y)
{
(x>y)?x:x=y;
return x;
}
int main()
{
int x,y,z,k;
cin>>x>>y>>z>>k;
cout<<"前两个数的最大值为:"<<max(x,y)<<endl;
cout<<"后三个数的最大值为:"<<max(y,z,k)<<endl;
cout<<"四个数的最大值为:"<<max(x,y,z,k)<<endl;
return 0;
}
Compare maximum (minimum)
You can use comparison expressions
((x>y)?x:x=y)>z?x:x=z;
return x;