C# Math.Cbrt() – Examples

In this tutorial, we will learn about the C# Math.Cbrt() method, and learn how to use this method to find the cube root of a specified number, with the help of examples.

Cbrt(Double)

Math.Cbrt(d) returns the cube root of a specified number d.

ADVERTISEMENT

Syntax

The syntax of Cbrt(Double)() method is

Math.Cbrt(Double d)

where

ParameterDescription
dThe number whose cube root is to be found.

Return Value

The method returns a Double value.

Example 1 – Cbrt(Double)

In this example, we will find the cube root of some numbers using Sqrt() method.

C# Program

using System;
 
class Example {
    static void Main(string[] args) {
        Double d, result;

        d = 2;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");

        d = 3;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");

        d = 4;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");

        d = 27;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");

        d = 64;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");

        d = 0.008;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");

        d = -27;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");

        d = Double.NegativeInfinity;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");

        d = Double.PositiveInfinity;
        result = Math.Cbrt(d);
        Console.WriteLine($"Cbrt({d}) = {result}");
    }
}

Output

Cbrt(2) = 1.25992104989487
Cbrt(3) = 1.44224957030741
Cbrt(4) = 1.5874010519682
Cbrt(27) = 3
Cbrt(64) = 4
Cbrt(0.008) = 0.2
Cbrt(-27) = -3
Cbrt(-∞) = -∞
Cbrt(∞) = ∞

Conclusion

In this C# Tutorial, we have learnt the syntax of C# Math.Cbrt() method, and also learnt how to use this method with the help of C# example programs.