原
#include <stdio.h>
int main()
{
int a, b, c;
printf("输入三个数:");
scanf("%d %d %d",&a, &b, &c);
if (a > b && a > c) {
printf("最大值为:%d\n",a);
}
else if (a > b && a < c)
{
printf("最大值为:%d\n",c);
}
else {
printf("最大值为:%d\n", b);
}
return 0;
}
优化
#include <stdio.h>
int findMax(int a, int b, int c) {
int max = a;
if (b > max)
max = b;
if (c > max)
max = c;
return max;
}
int main() {
int a, b, c;
printf("输入三个数: ");
scanf("%d %d %d", &a, &b, &c);
int max = findMax(a, b, c);
printf("最大值为: %d\n", max);
return 0;
}
标签:max,return,int,三数,最大值,C语言,printf,main
From: https://www.cnblogs.com/code3/p/17500202.html