慕码人8458602
2017-11-05 18:01
用if-else-if语句
#include<stdio.h> int main(){ int a,b,c,d,e;//e用来交换 scanf("%d%d%d%d",&a,&b,&c,&d); if(a<=b){e=a;a=b;b=e;}//此时a>b if(a<=c){e=a;a=c;c=e;}//此时a>c if(a<=d){e=a;a=d;d=e;}//此时a>d,此时a最大 if(b<=c){e=b;b=c;c=e;}//此时b>c if(b<=d){e=b;b=d;d=e;}//此时b>d,此时b第二 if(c<=d){e=c;c=d;d=e;}//此时c>d printf("%d %d %d %d",a,b,c,d); return 0; }
#include"stdio.h"
void main()
{
int a, b, c, d, t;
printf("输入四个整数");
scanf("%d %d %d %d",&a,&b,&c,&d);
if(a < b)
{
t = a; a = b; b = t;
}
else if(a < c )
{
t = a; a = c; c = t;
}
else if (a < d)
{
t = a; a = d; d = t;
}
else if( b < c)
{
t = b; b = c; c = t;
}
else if (b < d)
{
t = b; b = d; d = t;
}
else if (c < d)
{
t = c; c = d; d = t;
}
printf("%d %d %d %d",a,b,c,d);
}
#include<stdio.h>
int main ()
{
float a,b,c,d,e;
scanf("%f,%f,%f,%f",&a,&b,&c,&d);
if(a>b)
{
e=a;
a=b;
b=e;
}
if(a>c)
{
e=a;
a=c;
c=e;
}
if(a>d)
{
e=a;
a=d;
d=e;
}
//先确定最小的一个 a接下来判断bcd。
if(b>c)
{
e=b;
b=c;
c=e;
}
if(b>d)
{
e=d;
d=b;
b=e;
}
//使b为bcd最小的一个接下来判断c,d;
if(c>d)
{
e=c;
c=d;
d=e;
}
printf("%0.1f,%0.1f,%0.1f,%0.1f\n",d,c,b,a);
return 0;
}
C语言入门
926207 学习 · 20797 问题
相似问题