[华为机试-C++]101 求解立方根
8 个月前
· 来自专栏
华为机试 - C++
利维亚的施瓦辛格
热爱汽车的自动驾驶工程师
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
//f(x) = x^3-n = 0
double fcn(double x, double n) {
return x * x * x - n;
double dfcn(double x, double n) {
return 3 * x * x;
int main() {
double n, x, x_last;
cin >> n;
x = n;
while (1) {
x_last = x;
x = x - fcn(x,n) / dfcn(x,n);