最后一个大侠mp3:c 语言编程!

来源:百度文库 编辑:高考问答 时间:2024/04/28 00:27:31
用户输入三个数,按由小到大的顺序输出
我编写的程序对吗?
#include <stdio.h>
void main()
{
int a,b,c;
printf("请输入三个数:");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
printf("a>b\n");
else
if(a>c)
printf("a>c\n");
else
printf("b<c\n");
printf("%d,%d,%d",a,b,c);
}

你的a,b,c又没有经过排序,当然不对了。

#include <stdio.h>
void main()
{
int a,b,c;
printf("请输入三个数:");
scanf("%d%d%d",&a,&b,&c);
int temp;
if(a>b)
{temp=a;a=b;b=temp;}
if(b>c)
{temp=b;b=c;c=temp;}
if(a>b)
{temp=a;a=b;b=temp;}
printf("%d,%d,%d",a,b,c);
}

请把if else 体用{}起来,否则不易读,容易造成歧义