练习5-2 找两个数中最大者(10 分)
本题要求对两个整数a和b,输出其中较大的数。
函数接口定义:
| 1
 | int max( int a, int b );
 | 
其中a和b是用户传入的参数,函数返回的是两者中较大的数。
裁判测试程序样例:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 
 | #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;
 }
 
 
 
 | 
输入样例:
输出样例:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 
 | #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;
 }
 
 int max(int a, int b)
 {
 int result;
 if (a >= b)
 result = a;
 else
 result = b;
 
 return result;
 }
 
 |