第一章 习题6 编写一个程序,运行时输入a、b、c三个值,输出其中最大者
原创
©著作权归作者所有:来自51CTO博客作者会变聪明的的原创作品,如需转载,请与作者联系,否则将追究法律责任
方法1:
#include<stdio.h>
int main()
{
int a, b, c, max;
printf("Please enter three number: ");
scanf("%d,%d,%d", &a, &b, &c);
if (a > b){
if (a > c){
max = a;
}
else{
max = c;
}
}
else{
if (b > c){
max = b;
}
else{
max = c;
}
}
printf("max=%d\n", max);
}
方法2:
#include<stdio.h>
int main()
{
int a, b, c, max;
printf("Please enter three number: ");
scanf("%d,%d,%d", &a, &b, &c);
max = a > b ? (a > c ? a : c) : (b > c? b:c);
printf("max=%d\n", max);
}