Archived

This topic is now archived and is closed to further replies.

Cube Roots

This topic is 6349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

try this, im a begginer at C++ kinda, but I think this would work...

    
int cubeRoot(int a)
{
int b = 3
int 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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
try this, im a begginer at C++ kinda, but I think this would work...

    
int cubeRoot(int a)
{
int b = 3
int 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..


Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Or you could do it using the mathemathical equasion:

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

Dormeur

Share this post


Link to post
Share on other sites