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);
}
運行結果為:
新聞熱點
疑難解答