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;
}
}
|
#include<iostream>
#include<iomanip>
using namespace std;
void get_num(int &a,int &b,int &c)
{
cin>>a>>b>>c;
}
void max_min(int &max,int &min,int a,int b,int c)
{
max=a>b?a:b;
if(c>max)
max=c;
else
max=max;
min=a<b?a:b;
if(c<min)
min=c;
else
min=min;
}
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;
}
}