[算法笔记-题解]问题 D: 习题4-4 三个整数求最大值
问题 D: 习题4-4 三个整数求最大值
[命题人 : 外部导入]
时间限制 : 1.000 sec 内存限制 : 12 MB
题目描述
有3个整数a, b, c,由键盘输入,输出其中最大的数。
输入
以空格分割的三个整数。
输出
三个数中的最大值,末尾换行。
样例输入 Copy
1 3 2
样例输出 Copy
3
#include <stdio.h>
int compare(int a, int b, int c) {
if (a > b)
if (a > c)
return a;
else
return c;
else if (b < c)
return c;
else
return b;
}
int main() {
int one, two, three, Max;
scanf("%d%d%d", &one, &two, &three);
Max = compare(one, two, three);
printf("%d", Max);
return 0;
}
#include <stdio.h>
int main() {
int a, b, c, Max;
scanf("%d%d%d", &a, &b, &c);
Max = ((a > b) ? ((a > c) ? a : c) : ((b < c) ? c : b));
printf("%d", Max);
return 0;
}
Talk is cheap. Show me the code