c++结果错误 求助!
#include<stdio.h>int main()
{
int max;
int medium;
int min;
printf("请输入a,b,c的值");
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("a=%d\n",a);
printf("b=%d\n",b);
printf("c=%d\n",c);
if ( a > b ){
if ( b > c ){
int max = a;
int medium = b;
int min = c;
}else if( a > c ){
int max = a;
int medium = c;
int min = b;
}else{
int max = c;
int medium = b;
int min = a;
}
}else if( b < c ){
int max = c;
int medium = b;
int min = a;
printf("%d %d %d",max,medium,min);
printf("abc从大到小的排列顺序是%d>%d>%d",max,medium,min);
}else if( a > c){
int max = b;
int medium = a;
int min = c;
}else{
int max = b;
int medium = c;
int min = a;
}
printf("abc从大到小的排列顺序是%d>%d>%d",max,medium,min);
}
结果为什么不正常啊 #include<stdio.h>
int main()
{
int max;
int medium;
int min;
printf("请输入a,b,c的值");
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("a=%d\n",a);
printf("b=%d\n",b);
printf("c=%d\n",c);
if ( a > b ){
if ( b > c ){
int max = a; //因为这里又重新定义了 max, medium, min 一遍,在这里对这三个数的改变不影响外面三个数,所以最后打印的是一开始的 max, medium, min
int medium = b;
int min = c;
}else if( a > c ){
int max = a;
int medium = c;
int min = b;
}else{
int max = c;
int medium = b;
int min = a;
}
}else if( b < c ){
int max = c;
int medium = b;
int min = a;
printf("%d %d %d",max,medium,min);
printf("abc从大到小的排列顺序是%d>%d>%d",max,medium,min);
}else if( a > c){
int max = b;
int medium = a;
int min = c;
}else{
int max = b;
int medium = c;
int min = a;
}
printf("abc从大到小的排列顺序是%d>%d>%d",max,medium,min);
} 你试下在一开始打印一下 max, medium, min,看他们和最后打印的结果是否一样 qq1256740918 发表于 2019-9-2 22:40
你试下在一开始打印一下 max, medium, min,看他们和最后打印的结果是否一样
不一样
怎么是010
WiliWili 发表于 2019-9-2 22:44
不一样
怎么是010
懂了
谢谢
页:
[1]