题解 | #求解立方根#
求解立方根
https://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca
#include <iostream> using namespace std; int main() { double numInput; cin >> numInput; double x = 0; if(numInput >= 0) { while(x*x*x - numInput < 0) { x += 0.1; } if(numInput - (x-0.1)*(x-0.1)*(x-0.1) > x*x*x -numInput) { printf("%.1f",x); } else { printf("%.1f",x-0.1); } } else { while(x*x*x - numInput > 0) { x -= 0.1; } if((x+0.1)*(x+0.1)*(x+0.1) - numInput > numInput - x*x*x) { printf("%.1f",x); } else { printf("%.1f",x+0.1); } } } // 64 位输出请用 printf("%lld")