|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#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);
}
|
|