Calculate the Nth root of a number in C#

To calculate the Nth root of K you can simply use the formula:

    root = K1/N

The following code gets the numbers, calculates the root, and checks the result.

// Calculate the root.
private void btnCalculate_Click(object sender, EventArgs e)
{
double number = double.Parse(txtNumber.Text);
double root = double.Parse(txtRoot.Text);

// Calculate the root.
double result = Math.Pow(number, 1 / root);
txtResult.Text = result.ToString();

// Check the result.
double check = Math.Pow(result, root);
txtCheck.Text = check.ToString();
}

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.