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

求解立方根

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); } }

全部评论

相关推荐

有趣的牛油果开挂了:最近这个阶段收到些杂七杂八的短信是真的烦
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务