Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If the number (unm1) is the number entered by the user.
I tried I did not find the solution.
I am a novice programmer.
An example of attempts
double f = Math.Sqrt(Math.Sqrt(num1));
thanks!!!!
Posted
Comments
[no name] 28-Nov-14 9:13am    
Cube root is defined as x^1/3 so you can use Math.Pow(unm1, 1.0/3.0)
haloolal 28-Nov-14 9:37am    
Thank you very much
[no name] 28-Nov-14 11:16am    
You're welcome.

The square root of a square root isn't a cube root:
The Cube of x = y * y * y
or x = y3
But if:
Sqrt(Sqrt(x)) == y
Then
Sqrt(x) = y * y
And
x = (y * y) * (y * y)
or x = y4

So as Bruno says:
C#
private double CubeRoot(double x)
    {
    return Math.Pow(x, (1.0 / 3.0));
    }
 
Share this answer
 
Comments
haloolal 28-Nov-14 9:35am    
Thank you very much
OriginalGriff 28-Nov-14 9:49am    
You're welcome!
[no name] 29-Nov-14 6:02am    
My 5 also because you explain OP where/why he is wrong.

One small question: how you managed to show exponent that nice?
OriginalGriff 29-Nov-14 6:19am    
"One small question: how you managed to show exponent that nice?"
HTML tag characters don't always work too well in comments, so...

less-than sup greater-than exponent value less-than /sup greater-than

x[sup]4[/sup]
[no name] 29-Nov-14 6:26am    
Great, thank you very much! For answers it works perfect :)

let's see now in comment: x4
A simple way using the .NET Framework's System.Math.Pow method:
C#
public double CubeRoot(double d)
{
    return (System.Math.Pow(d, (1.0/3.0)));
}
 
Share this answer
 
v5
Comments
[no name] 28-Nov-14 9:23am    
Ends unfortunately in 1 because 1/3 == 0. Better 1.0/3.0 ;)
haloolal 28-Nov-14 9:31am    
hi,

The result is shown a number (1).
TheRealSteveJudge 28-Nov-14 9:33am    
void methods do not return anything.
[no name] 28-Nov-14 9:36am    
well recognized ;)
haloolal 28-Nov-14 9:36am    
Thank you very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900