C# Program - Cube Root of a Number


Advertisements

If a number is multiplied by itself two times ($$n*n*n$$), the final number will be the cube of that number and inding the cube root of a number is inverse operation of cubing the number. If x is the cube root of y, it can be expressed as below:

$$x = \sqrt[3]{y}$$

Alternatively, it can also be expressed as:

$$x^3 = y$$

Example: Using Pow() method of C# Math Class

The pow() method of cs Math class can be used to calculate cube root of a number.

using System;

namespace MyApplication { 
  class MyProgram {
    static void Main(string[] args) {
	  double x = 64;
	  double y = 125;

	  //Pow() takes double datatype as argument
	  double x1 = Math.Pow(x, 1/3.0);
	  double y1 = Math.Pow(y, 1/3.0);
	  Console.WriteLine("Cube root of " + x + " is " + x1);
	  Console.WriteLine("Cube root of " + y + " is " + y1);
    }
  }
}

Output

Cube root of 64 is 4
Cube root of 125 is 5

Advertisements