方法一:
代码:
#include<stdio.h>
int main()
{
int a, b, c, max;
scanf("%d %d %d", &a, &b, &c);
if (a >= b && a >= c)
max = a;
if (b >= a && b >= c)
max = b;
if (c >= a && c >= b)
max = c;
printf("%d", max);
return 0;
}
输入数字时需要用空格隔开,例如6 3 9。
结果:
———————————————————————————————————————————
方法二:
代码:
#include<stdio.h>
int main()
{
int a, b, c, max;
scanf("%d%d%d", &a, &b, &c);
max = a;
if (b > max)
max = b;
if (c > max)
max = c;
printf("max=%d", max);
}
结果:
———————————————————————————————————————————
方法三:(函数)
代码:
int max(int x,int y)
{
return(x>y)?x:y;
}
#include<stdio.h>
int main()
{
int max(int x, int y);
int a, b, c, d;
scanf_s("%d%d%d", &a, &b, &c);
d = max(max(a,b),c);
printf("max=%d", d);
return 0;
}
结果: