[C# Helper]
Index Books FAQ Contact About Rod
[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Calculate Nth roots in C#

[Calculate Nth roots in C#]

To calculate Nth roots, you can simply use the formula:

    root = K1/N

The example program uses the following code to calculate roots.

// 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(); }

The code parses the number and the root. It uses Math.Pow to raise the number to the 1/root power and displays the result. To check the result, the code then raises the result to the root power and displays the new result.

Download the example to experiment with it and to see additional details.

© 2009-2022 Rocky Mountain Computer Consulting, Inc. All rights reserved.