C语言编程题,选择结构If语句
展开全部
我用的是笨方法:先把a分别与b,c,d相比较,最小的值赋给a,然后b与c,d比较,最小的给b,然后c与d比较,较小的赋给c
#include<stdio.h>
void
main()
{
int
a,b,c,d,t;
printf("please
input
four
number
:");
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a>b)
{
t
=
a;
a
=
b;
b
=
t;
}
if(a>c)
{
t
=
a;
a
=
c;
c
=
t;
}
if(a>d)
{
t
=
a;
a
=
d;
d
=
t;
}
if(b>c)
{
t
=
b;
b
=
c;
c
=
t;
}
if(b>d)
{
t
=
b;
b
=
d;
d
=
t;
}
if(c>d)
{
t
=
c;
c
=
d;
d
=
t;
}
printf("%d
%d
%d
%d",a,b,c,d);
}
#include<stdio.h>
void
main()
{
int
a,b,c,d,t;
printf("please
input
four
number
:");
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a>b)
{
t
=
a;
a
=
b;
b
=
t;
}
if(a>c)
{
t
=
a;
a
=
c;
c
=
t;
}
if(a>d)
{
t
=
a;
a
=
d;
d
=
t;
}
if(b>c)
{
t
=
b;
b
=
c;
c
=
t;
}
if(b>d)
{
t
=
b;
b
=
d;
d
=
t;
}
if(c>d)
{
t
=
c;
c
=
d;
d
=
t;
}
printf("%d
%d
%d
%d",a,b,c,d);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询