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

来源:互联网 发布:中老年人运动装淘宝网 编辑:程序博客网 时间:2024/05/16 12:12
#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;
阅读全文
0 0
原创粉丝点击