- ·上一篇文章:编写程序求分段函数的值
- ·下一篇文章:VC制作软件启动画面的方法
由键盘输入3个整数a,b,c,求出最大值
:2011-03-20 09:17:44
C语言练习题:
有3个整数a,b,c,由键盘输入,输出其中最大值。
方法一:
main()
{
int a,b,c;
printf("Please input 3 integer number;");
scanf("%d,%d,%d",&a,&b,&c);
if(a<b)
if(b<c)
printf("max=%d\n",c);
else
printf("max=%d\n",b);
else if(a<c)
printf("max = %d\n",c);
else
printf("max=%d\n",a);
}
运行结果为:
方法二:使用条件表达式
main()
{
int a,b,c,temp,max;
printf("Please input 3 integer number;");
scanf("%d,%d,%d",&a,&b,&c);
temp = (a>b)?a:b;
max = (temp>c)?temp:c;
printf("The maximum number is %d",max);
}
运行结果为:
由键盘输入3个整数a,b,c,求出最大值