The source code to find the cube root of a given number is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//C# program to find the cube root of a specified number.
using System;
class CubeRoot
{
static int Main()
{
int number = 0;
double cubeRoot= 0;
Console.Write("Enter the value of number: ");
number = Convert.ToInt32(Console.ReadLine());
cubeRoot = Math.Ceiling(Math.Pow(number, (double)1 / 3));
Console.WriteLine("Cube Root is : " + cubeRoot);
return 0;
}
}
Output:
Enter the value of number: 27
Cube Root is : 3
Press any key to continue . . .
Explanation:
Here, we created a class CubeRoot that contains the Main() method. The Main() method is an entry point for the program. Here we created two variables number and cubeRoot that are initialized with 0. Then we read the value of the variable number. After that calculated the cube root using Pow() method and then printed the cube root on the console screen.
Program:
The source code to find the cube root of a given number is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created a class CubeRoot that contains the Main() method. The Main() method is an entry point for the program. Here we created two variables number and cubeRoot that are initialized with 0. Then we read the value of the variable number. After that calculated the cube root using Pow() method and then printed the cube root on the console screen.