您的位置:首页 > 其它

求2个或3个正整数中的最大值,用带有默认参数的函数实现

2017-11-20 17:24 6088 查看
#include<iostream>
using namespace std;
int main()
{
int max(int a,int b,int c=0);
{
int a,b,c;
cin>>a>>b>>c;
cout<<"max_3="<<max(a,b,c)<<endl;
cout<<"max_2="<<max(a,b)<<endl;
return 0;
}
}
int max(int a,int b,int c)
{
if(b>a) a=b;
if(c>a) a=c;
return a;
}
输入 1 2 3
输出 max_3=3;
max_2=2;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  函数
相关文章推荐