简单C程序:给随机三个数由大到小排序,求高手检查错误,
#include<stdio.h>
int main()
{
int a,b,c;
printf("Please input three integers:");
scanf("%d%d%d",&a,&b,&c);
if(a>=b)
if(b>=c)
printf("The number from small to large sort is:%d>%d>%d\n",a,b,c);
else
printf("The number from small to large sort is:%d>%d>%d\n",a,c,b);
else if(b>=a)
if(a>=c)
printf("The number from small to large sort is:%d>%d>%d\n",b,a,c);
else
printf("The number from small to large sort is:%d>%d>%d\n",b,c,a);
else if(c>=a)
if(a>=b)
printf("The number from small to large sort is:%d>%d>%d\n",c,a,b);
else
printf("The number from small to large sort is:%d>%d>%d\n",c,b,a);
}
简单C程序:给随机三个数由大到小排序,求高手检查错误,
答案:1 悬赏:10 手机版
解决时间 2021-08-13 19:27
- 提问者网友:回忆在搜索
- 2021-08-13 05:19
最佳答案
- 五星知识达人网友:上分大魔王
- 2021-08-13 05:45
你的程序逻辑判断上有问题
你检查下if(a>=b)这个语句里面的if-else语句:
如果a>=b,在b>=c不成立时,并不能说明a>=c>=b
再问: 请问,怎么修改
再答: 你把逻辑理清就行了:#include<stdio.h>
int main()
{
int a,b,c;
printf("Please input three integers:");
scanf("%d%d%d",&a,&b,&c);
if(a>=b)
if(b>=c)
printf("The number from small to large sort is:%d>=%d>=%d\n",a,b,c);
else if(a>=c)
printf("The number from small to large sort is:%d>=%d>=%d\n",a,c,b);
else
printf("The number from small to large sort is:%d>=%d>=%d\n",c,a,b);
else
if(a>=c)
printf("The number from small to large sort is:%d>=%d>=%d\n",b,a,c);
else if (b>=c)
printf("The number from small to large sort is:%d>=%d>=%d\n",b,c,a);
else
printf("The number from small to large sort is:%d>=%d>=%d\n",c,b,a);
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯