新手来问:用if语句进行几个数比较大小,有更简单的方法吗?
#include<stdio.h>int main()
{
int a,b,c,d,e,f;
scanf("%d,%d,%d,%d",&a,&b,&c,&d);
if(a>b)
e=a;
else e=b;
if(e>c)
f=e;
else
f=c;
if(f>d)
printf("max=%d\n",f);
else
printf("max=%d\n",d);
return 0;
}
2012-03-19 11:57
2012-03-19 12:23
程序代码:#include<stdio.h>
int main()
{
int a,b,c,d,max;
scanf("%d,%d,%d,%d",&a,&b,&c,&d);
max = a;
if (max < b)
max = b;
if(max < c)
max = c;
if(max < d)
max = d;
printf("max=%d\n",max);
return 0;
}
2012-03-19 12:31
程序代码:#include<stdio.h>
int main()
{
int temp;
int i;
int temp1=0,temp2=0,max=0,min=0;
for(i=0;i<6;i++)
{
scanf("%d",&temp);
}
if(temp>=max){temp1=temp;temp=max;max=temp1;}
if(temp<=min){temp2=temp;temp=max;max=temp2;}
printf("%d %d\n",max,min);
return 0;
}

2012-03-19 12:38
2012-03-19 12:43
2012-03-19 15:45
2012-03-19 16:25
2012-03-19 17:55
2013-03-25 20:22

2013-03-25 22:41