The Pythagorean theorem states that the sun of the squares of the sides of a right triangle is equal to the square of the hypotenuse. Given two positive integers, m and n, where m>n, a Pythagorean triple can be generated by the following formulas:
Side 1= m2 - n2
Side 2 = 2mn
Hypotenuse = m2 + n2
Write a program in visual basics that reads in values for m and n and prints the values of the Pythagorean triple generated by these formulas
Module Module1
Sub Main()
Console.Write("Enter n: ")
Dim n As Integer = Integer.Parse(Console.ReadLine())
Dim m As Integer = n - 1
While (m < n)
Console.Write("Enter m > n: ")
m = Integer.Parse(Console.ReadLine())
End While
Dim Side1 As Integer = m * m - n * n
Dim Side2 As Integer = 2 * m * n
Dim Hypotenuse As Integer = m * m + n * n
'prints the values of the Pythagorean triple generated by these formulas
Console.WriteLine(vbNewLine + "Side 1: " + Side1.ToString())
Console.WriteLine("Side 2: " + Side2.ToString())
Console.WriteLine("Hypotenuse: " + Hypotenuse.ToString())
Console.ReadLine()
End Sub
End Module
Comments
Leave a comment