题解 | #求解立方根#
求解立方根
https://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca
#include <iostream> using namespace std; double solve(double num){ double a = -20; double b = 20; double c = 0; while(b-a>=0.05){ if(c*c*c >num){ b = c ; } else { a = c; } c = (a+b)/2; } if(c>0){ //感觉这个题最麻烦的是怎么判断正负 c =(int)(c*10 +0.5)/10.0; }else c =(int)(c*10 - 0.5)/10.0; return c; } int main() { double s; cin >> s; cout << solve(s); } // 64 位输出请用 printf("%lld")