三个数顺序排大小的问题!不懂,求教!
#include<stdio.h>void main()
{
int a,b,c,temp;
printf("input three numbers:");
scanf("%d %d %d",&a,&b,&c);/*问题1:顺序输入10 20 30结果为什么是10 30 20*/
if(a>b)/*问题2:a=10,b=20条件不成立为什么还会执行花括号里的内容*/
{
temp=a;
a=b;
b=temp;
}
if(a>c)/*a=10,c=30这也不成立*/
{
temp=a;
a=c;
c=temp;
}
if(b>c);/*b=20,c=30这也不成立*/
{
temp=b;
b=c;
c=temp;
}
printf("%d %d %d\n",a,b,c);
}
#include<stdio.h>
#define N 3
int main()
{
int n;
int i,j,t;
printf("Please Input number:");
for(i = 0;i<N;i++)//输入N个数字
{
scanf("%d",&n);
}
for(i = 0;i<N;i++)//冒泡排序
{
for(j = i+1;j<N;j++)
{
if(n>n)
{
t = n;
n = n;
n = t;
}
}
}
for(i = 0;i<N;i++)//输出
{
printf("%-5d",n);
}
return 0;
} 你交换顺序了以后A,B,C的值已经变了,所以你重新打印一边的值顺序就变了,不满足IF条件是不会执行里面的语句的
页:
[1]