呵呵,很简单的问题呀,我这里有四种方法,你参考一下
#include
void main()
{
int a,b,c,max; //这里只能为整形,不能为double型
printf("please input three number a,b,c:\n");
scanf("%d%d%d",&a,&b,&c);
// method one:
max=a;
if(b>=max) max=b;
if(c>=max) max=c;
printf("the max is:%d\n",max);
// method two:
if(a>=b&&a>=c)
printf("the max is %d\n",a);
else if(b>=a&&b>=c)
printf("the max is %d\n",b);
else
printf("the max is %d\n",c);
// method three:
printf("the max is: %d\n",a>=b&&a>=c?a:(b>=a&&b>=c?b:c));
// method four:
int a[3],max=-32768;
for(int i=0;i<3;i++)
{
scanf("%d",&a[i]);
if(a[i]>max) max=a[i];
}
printf("the max is:%d\n",max);
}
取消
评论