4个数比较大小,结果从小到大排列,用C语言if语句怎么编?#includeint main(){int a,b,c,d,e;scanf("%d,%d,%d,%d",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;}if(b>c){e=b;b=c;c=e;}if(b>d){e=b;b=d;d=e;}if(c>d){e=
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 05:26:28
4个数比较大小,结果从小到大排列,用C语言if语句怎么编?#includeint main(){int a,b,c,d,e;scanf("%d,%d,%d,%d",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;}if(b>c){e=b;b=c;c=e;}if(b>d){e=b;b=d;d=e;}if(c>d){e=
4个数比较大小,结果从小到大排列,用C语言if语句怎么编?
#include
int main()
{
int a,b,c,d,e;
scanf("%d,%d,%d,%d",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;
}
if(b>c)
{
e=b;
b=c;
c=e;
}
if(b>d)
{
e=b;
b=d;
d=e;
}
if(c>d)
{
e=c;
c=d;
d=e;
}
printf("%d,%d,%d,%d\n",a,b,c,d);
return 0;
}
我编的这个运行时,第四个数(d)比不出大小,请问这个错在哪里?
4个数比较大小,结果从小到大排列,用C语言if语句怎么编?#includeint main(){int a,b,c,d,e;scanf("%d,%d,%d,%d",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;}if(b>c){e=b;b=c;c=e;}if(b>d){e=b;b=d;d=e;}if(c>d){e=
算法上没错,能得到想要的结果,这就是冒泡算法.在用scanf变量输入时要给他变量地址,用取地址符:&,如int a; scanf(''a=%d'',&a);