点击(此处)折叠或打开
- #include "stdio.h"
- #include <math.h>
- double myround(double x);
- int main(void)
- {
- double x;
- printf("(正负小数四舍五入)请输入小数:");
- scanf("%lf",&x);
- printf("四舍五入后为:%lf",myround(x));
- return 0;
- }
- double myround(double x)
- {
- int i = (int)x;
- if(x>0){
- if((x-i)<0.5 && (x-i)>0)
- return ceil(x)-1;
- else
- return ceil(x);
- }else if(x<0){
- if(fabs((x-i))<0.5 && fabs((x-i))>0)
- return floor(x)+1;
- else
- return floor(x);
- }else
- return 0.0;
- }
相关热门文章
给主人留下些什么吧!~~
评论热议