面向对象程序设计上机练习三(有默认参数的函数)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
利用默认参数的函数实现求2个或3个整数的最大值。
Input
输入3个int型整数。
Output
输出第1、2个整数及其最大值;
输出第1、2、3个整数及其最大值。
输出第1、2、3个整数及其最大值。
Example Input
88 66 99
Example Output
88 66 88 88 66 99 99
Hint
Author
//在C++中,有默认值的在最后写,因为实参值从左到右赋值
#include<bits/stdc++.h>
using namespace std;
int maxx(int x, int y, int z = 0)
{
int a = x;
if(y > x)
a = y;
if(z > a)
a = z;
return a;
}
int main()
{
int x, y, z;
cin>>x>>y>>z;
cout<<x<<" "<<y<<" "<<maxx(x, y)<<endl;
cout<<x<<" "<<y<<" "<<z<<" "<<maxx(x, y, z)<<endl;
return 0;
}