简单C程序:给随机三个数由大到小排序,求高手检查错误,
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/10 15:24:27
简单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);
}
#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);
}
你的程序逻辑判断上有问题
你检查下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(b>=a)*/
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);
/*
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);
*/
}
你检查下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(b>=a)*/
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);
/*
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程序:给随机三个数由大到小排序,求高手检查错误,
三个数从小到大排序的JAVA程序
跪求检查matlab程序中的错误
C语言:编写一个程序,实现将三个数进行排序,并显示输出.
三个数从小到大排序描述 现在要写一个程序,实现给三个数排序的功能输入 输入三个正整数 输出 给输入的三个正整数排序 样例
C语言中从键盘上输入三个数,将之排序后按由大到小的顺序输出
求英语高手,改句子,检查错误
急求谢啦C语言编程 按从大到小排序三个数
编写程序,输入三个整数a,b和c,按由小至大的顺序排序输出
C语言 输入三个数 按由小到大排序 函数调用的方法
求一个C语言程序:交换三个数的值.
C语言ABC三个数从小到大排序