练习5-2 找两个数中最大者 (10 point(s))

本题要求对两个整数a和b,输出其中较大的数。

函数接口定义:

int max( int a, int b );

其中a和b是用户传入的参数,函数返回的是两者中较大的数。

裁判测试程序样例:

#include <stdio.h>

int max( int a, int b );

int main()
{
    
        
    int a, b;

    scanf("%d %d", &a, &b);
    printf("max = %d\n", max(a, b));

    return 0;
}
/* 你的代码将被嵌在这里 */

输入样例:

5 8

输出样例:

max = 8

题解:

int max( int a, int b )
{
    
     
	if(a>b) return a; //如果a大,就把a的值返回给max。反之返回b的值
	else return b;
}

猜你喜欢

转载自blog.csdn.net/qq_44715943/article/details/114583030
今日推荐