编写函数:三个数的最大最小值 (Append Code)

Description

给出三个数a,b,c,最大值是?最小值是?

-----------------------------------------------------------------------------

编写以下两个函数:

get_num()的功能是读取输入的三个整数a,b,c;

max_min()的功能是求出a,b,c的最大值和最小值。

以上函数的调用格式见“Append Code”。这里不给出函数原型,请通过main()函数自行确定。

Input

输入的第一个整数n,表示有n组测试数据,每组3个整数:a,b,c。a,b,c都在int类型范围内。

Output

每组测试数据对应输出一行:为a,b,c的最大值和最小值,格式见sample。

Sample Input

520 15 1010 15 20100 100 00 1 -10 0 0

Sample Output

case 1 : 20, 10case 2 : 20, 10case 3 : 100, 0case 4 : 1, -1case 5 : 0, 0

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;
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值