Answer to Question #170607 in Visual Basic for Osanyinlusi Emmanuella

Question #170607

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


1
Expert's answer
2021-04-01T02:20:41-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS