C语言实现找两个数中最大者

练习5-2 找两个数中最大者(C语言)

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

函数接口定义:int max (int a,int b);

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

分析:可利用三目运算符直接返回最大值。

#include <stdio.h>
int max(int a,int b);
int max(int a,int b){
	return a>b?a:b;
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("max = %d",max(a,b));
	return 0;
}