老师给小平留作业,计算三个数中第二大的数。小平希望你帮他完成。要求输入三个数,分别求出int、long和double型的值。
部分代码已给定如下,只需要提交缺失的代码。
#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型的三个数。每个类型的三个数占一行。
输出
依次输出int、long和double型的中间值。每个值占一行。
样例输入
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]的警告,真心求解怎么消除它。