0
Create Function for cube root
I need To create a function to find cube root?
3 ответов
0
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int num;
cin>>num;
int cubeRoot=cbrt(num);
cout<<"Cube root of "<<num<<" is "<<cubeRoot <<endl;
return 0;
}
0
I need a function without cmath.
Function by use for loop.
0
You could use the Babylonian algorithm for a sqrt adapted for cbrt
Let's consider y = cbrt(x+k)
You can see that when x=0 than y=cbrt(k)
Which translates to finding the zeros of the inverse function:
y^3 - k = x
We can use Newton's method:
next = prev - f(prev)/f'(prev)
Here f(y) = y^3-k
And f'(y) = 3y^2 (the derivative of f)
At the end you should get
next = (2prev + k/prev^2)/3