作业帮 > 综合 > 作业

本程序用于实数返还指定小数位数的四舍五入后的值.但程序中存在若干错误,请你纠正

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/09/04 21:43:56
本程序用于实数返还指定小数位数的四舍五入后的值.但程序中存在若干错误,请你纠正
#include
int round(float x,int n)
{ float z;
long i;
i=pow(10,n);
z=(long)(x*i+0.5)/(float)i;
return i;
}
main()
{ float x,y;
int n;
printf("input x n\n");
scanf("%f%d",&x,&n);
y=round(x,n);
printf("x=%f,round(%f)=%f\n",x,x,y);
}
#include
#include
float round(float x,int n)
{
float z;
long i;
i=(long)pow(10,n);
z=(long)(x*i+0.5)/(float)i;
return z;
}
void main()
{
float x,y;
int n;
printf("input x n\n");
scanf("%f%d",&x,&n);
y=round(x,n);
printf("x=%f,round(%f)=%f\n",x,x,y);
}