新手来问:用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;
}
#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; }
#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; }