|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打印最小的输入数字
我想用int 来定义a,b,c但是最后打印的时候结果一直是0,只有用doble才能正常运行,但是也不能输出小数点的数字
请大神帮忙看下哪个代码有问题,谢谢!
#include<stdio.h>
main(){
double a,b,c;
double smallest;
printf("input the first number\n");
scanf("%f", &a);
printf("input the second number\n");
scanf("%f", &b);
printf("input the third number\n");
scanf("%f", &c);
if(a<b){
if(a<c){
a=smallest;
}else{
c=smallest;
}
}else{
if(b<c){
b=smallest;
}else{
c=smallest;
}
}
printf("The smallest the number is %d\n",smallest);
}
- #include<stdio.h>
- main(){
- int a,b,c;
- int smallest;
- printf("input the first number\n");
- scanf("%d", &a);
- printf("input the second number\n");
- scanf("%d", &b);
- printf("input the third number\n");
- scanf("%d", &c);
- if(a<b){
- if(a<c){
- smallest=a; //赋值的时候应该把变量放左边
- }else{
- smallest=c;
- }
- }else{
- if(b<c){
- smallest=b;
- }else{
- smallest=b;
- }
- }
- printf("The smallest the number is %d\n",smallest);
- }
复制代码
|
|