【十二题解】 | #求解立方根#

求解立方根

http://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca

#include<stdio.h>

void cube(double a){ double right = a; double left = 0.0; double ret = (right+left)/2.0; if(a>0){ if(a<1){ left = 0.0; right = 1.0; } for(ret = (right+left)/2.0; fabs(retretret-a)>0.01; ret = (right+left)/2.0){ if(retretret>a){ right = ret; } else{ left = ret; } } printf("%.1lf", ret); } else if(a<0){ if(a>-1){ left = 0.0; right = -1.0; } for(ret = (right+left)/2.0; fabs(retretret-a)>0.01; ret = (right+left)/2.0){ if(retretret<a){ right = ret; } else{ left = ret; } } printf("%.1lf", ret); } else{ printf("0.0"); }

}

int main(){ double num; while(scanf("%lf", &num) != EOF){ cube(num); } }

全部评论

相关推荐

尊尼获获:闺蜜在哪?
点赞 评论 收藏
分享
已老实求offer😫:有点像徐坤(没有冒犯的意思哈)
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务