编写函数float fun(double x),使得x的值保留2位小数,并对第3位四舍五入(x中值为正数)
·fun函数代码如下
double fun(double h){
double b=(int)(h*100)/100.0;
printf("%lf\n",b);
if((int)(h*1000)%10>=5){
b=(int)(100*h+1)/100.0;
}
printf("%lf\n",b);
return b;
}
编写函数float fun(double x),使得x的值保留2位小数,并对第3位四舍五入(x中值为正数)
·fun函数代码如下
double fun(double h){
double b=(int)(h*100)/100.0;
printf("%lf\n",b);
if((int)(h*1000)%10>=5){
b=(int)(100*h+1)/100.0;
}
printf("%lf\n",b);
return b;
}