取近似值
取近似值
http://www.nowcoder.com/questionTerminal/3ab09737afb645cc82c35d56a5ce802a
利用int整型向下取整,float数加0.5后强制int类型转换
include<stdio.h>
int main(){
float num;
scanf("%f",&num);
printf("%d\n",(int)(num +0.5));
return 0;
}
取近似值
http://www.nowcoder.com/questionTerminal/3ab09737afb645cc82c35d56a5ce802a
利用int整型向下取整,float数加0.5后强制int类型转换
int main(){
float num;
scanf("%f",&num);
printf("%d\n",(int)(num +0.5));
return 0;
}
相关推荐