How to find pythagorean triplet for which a + b + c = 1000 in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Sub Main(ByVal args As String())
        Const sum As Integer = 1000

        For a As Integer = 1 To sum / 3
            For b As Integer = a + 1 To sum / 2
                Dim c As Integer = sum - a - b
                If a * a + b * b = c * c Then
                    Console.Write("a = " & a & " b = " & b & " c = " & c)
                End If
            Next
        Next
    End Sub
End Class


' (200 ^ 2 = 40000) + (375 ^ 2 = 140625) = 180625 = 425 ^ 2


' run:
'
' a = 200 b = 375 c = 425
'

 



answered Oct 23, 2023 by avibootz
...