|
|
Title | Calculate the Nth root of a number in Visual Basic .NET |
Description | This example shows how to calculate the Nth root of a number in Visual Basic .NET. |
Keywords | mathematics, roots, square roors, cube roots, find roots, Exp, Log, Visual Basic .NET, VB.NET |
Categories | Algorithms |
|
|
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 Sub btnCalculate_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
btnCalculate.Click
Dim number As Double = Double.Parse(txtNumber.Text)
Dim root As Double = Double.Parse(txtRoot.Text)
' Calculate the root.
Dim result As Double = Math.Pow(number, 1 / root)
txtResult.Text = result.ToString()
' Check the result.
Dim check As Double = Math.Pow(result, root)
txtCheck.Text = check.ToString()
End Sub
|
|
|
|
|
|
|
|
|