面向对象程序设计上机练习三(有默认参数的函数)

来源:互联网 发布:桌面录屏软件 编辑:程序博客网 时间:2024/06/05 18:46

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

有默认参数的函数整理:http://blog.csdn.net/gx17864373822/article/details/78347169

#include <iostream>using namespace std;int max(int a,int b,int c=0)//默认值c=0,不传进c时,使用默认值c=0{    int maxx=a;    if(b>maxx)        maxx=b;    if(c>maxx)//不能用else if        maxx=c;    return maxx;}int main(){    int a,b,c;    cin>>a>>b>>c;   cout<<a<<" "<<b<<" "<<max(a,b)<<endl;   cout<<a<<" "<<b<<" "<<c<<" "<<max(a,b,c)<<endl;    return 0;}
阅读全文
0 0