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