OJ刷题之《函数重载-求中间值》

老师给小平留作业,计算三个数中第二大的数。小平希望你帮他完成。要求输入三个数,分别求出intlongdouble型的值。
部分代码已给定如下,只需要提交缺失的代码。
#include <iostream>
using namespace std;
int  main()
{
    int show(int,int,int);
    long show(long,long,long);
    double show(double,double,double);

    int a1,b1,c1;
    cin>>a1>>b1>>c1;
    int maxt1=show(a1,b1,c1);
    cout<<"int:"<<maxt1<<endl;

    long a2,b2,c2;
    cin>>a2>>b2>>c2;
    long maxt2=show(a2,b2,c2);
    cout<<"long:"<<maxt2<<endl;

    double a3,b3,c3;
    cin>>a3>>b3>>c3;
    double maxt3=show(a3,b3,c3);
    cout<<"double:"<<maxt3<<endl;
  
}

输入

依次输入int型、long型、double型的三个数。每个类型的三个数占一行。

输出

依次输出intlongdouble型的中间值。每个值占一行。

样例输入

1 2 3

2345 1234 3456

1.11 3.22 2.22

 

 

代码如下:

#include <iostream>
using namespace std;

int  main()
{
    int show(int,int,int);
    long show(long,long,long);
    double show(double,double,double);

    int a1,b1,c1;
    cin>>a1>>b1>>c1;
    int maxt1=show(a1,b1,c1);
    cout<<"int:"<<maxt1<<endl;

    long a2,b2,c2;
    cin>>a2>>b2>>c2;
    long maxt2=show(a2,b2,c2);
    cout<<"long:"<<maxt2<<endl;

    double a3,b3,c3;
    cin>>a3>>b3>>c3;
    double maxt3=show(a3,b3,c3);
    cout<<"double:"<<maxt3<<endl;
    return 0;
}

int show(int a,int b,int c)
{
    if ((b>a&&a>c)||(c>a&&a>b))
        return a;
    else if ((a>b&&b>c)||(c>b&&b>a))
        return b;
    else if ((a>c&&c>b)||(b>c&&c>a))
        return c;
}

long show(long a,long b,long c)
{

    if ((b>a&&a>c)||(c>a&&a>b))
        return a;
    else if ((a>b&&b>c)||(c>b&&b>a))
        return b;
    else if ((a>c&&c>b)||(b>c&&c>a))
        return c;
}

double show(double a,double b,double c)
{
    if ((b>a&&a>c)||(c>a&&a>b))
        return a;
    else if ((a>b&&b>c)||(c>b&&b>a))
        return b;
    else if ((a>c&&c>b)||(b>c&&c>a))
        return c;
}


 

运行结果:

 

 

还是会有control reaches end of non-void function [-Wreturn-type]的警告,真心求解怎么消除它。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值