Description
给出三个数a,b,c,最大值是?最小值是?
-----------------------------------------------------------------------------
编写以下两个函数:
get_num()的功能是读取输入的三个整数a,b,c;
max_min()的功能是求出a,b,c的最大值和最小值。
以上函数的调用格式见“Append Code”。这里不给出函数原型,请通过main()函数自行确定。
Input
Output
Sample Input
Sample Output
HINT
Append Code
int
main()
{
int
cases;
int
mmax, mmin, a, b, c;
cin>>cases;
for
(
int
i = 1; i <= cases; ++i)
{
get_num(a, b, c);
max_min(mmax, mmin, a, b, c);
cout<<
"case "
<<i<<
" : "
<<mmax<<
", "
<<mmin<<endl;
}
}
using namespace std;
int get_num(int &a,int &b,int &c)
{
cin>>a>>b>>c;
}
int max_min(int &mmax,int &mmin,int &a,int &b,int &c)
{
int t;
if(b>a){t=a;a=b;b=t;}
if(c>a){t=a;a=c;c=t;}
if(b<c){t=c;c=b;b=t;}
mmax=a;
mmin=c;
}
int main()
{
int cases;
int mmax, mmin, a, b, c;
cin>>cases;
for(int i = 1; i <= cases; ++i)
{
get_num(a, b, c);
max_min(mmax, mmin, a, b, c);
cout<<"case "<<i<<" : "<<mmax<<", "<<mmin<<endl;
}
}