Cube Roots

Started by
5 comments, last by Smack0007 23 years, 7 months ago
How do you get the cube root of something? zac@qisfl.net
Snowsoft Online
I don't pretend to know anything.
- I don't pretend to know anything.Snowsoft
Advertisement
try this, im a begginer at C++ kinda, but I think this would work...

    int cubeRoot(int a){int b = 3int c = 0;for(b=0; b<4; b++){c += a*a}return a;} 


then use like

int x = cubeRoot(4); 


I think that should work..

Edited by - uG on August 30, 2000 7:08:38 PM
pow( x, .33 )?

in many cases, this will only work if x is positive.


Edited by - Antknei on August 30, 2000 7:10:30 PM
try this, im a begginer at C++ kinda, but I think this would work...

    int cubeRoot(int a){int b = 3int c = 0;for(b=1; b<4; b++){c += a*a}return a;}  


then use like

int x = cubeRoot(4);  


I think that should work..


Your equation ends up with c = 3a^2. but it returns a, which you don''t change. Am I missing something, or did you mistype something?
Like Antknei was saying, to get the nth root of a number x, use pow(x, 1/n). As far as I know, the only time you get an error returned from this function is when you try to raise zero to a negative power, as this would be equivalent to division by zero.

-Ironblayde
Aeon Software
"Your superior intellect is no match for our puny weapons!"
Or you could do it using the mathemathical equasion:

n root of x = exp(log(x)/n)

Dormeur
Wout "Dormeur" NeirynckThe Delta Quadrant Development Page

This topic is closed to new replies.

Advertisement