Triángulos Pitagóricos y programa en Microsoft Small Basic para encontrarlos.
Los Triángulos Pitagóricos tienen todos sus lados enteros: Hipotenusa entera y ambos Catetos enteros.
3. 3
' TRIÁNGULOS PITAGÓRICOS
TextWindow.WriteLine("TRIÁNGULOS PITAGÓRICOS")
TextWindow.WriteLine("i = Valor Máximo de los Catetos = ")
i = TextWindow.ReadNumber()
n = 0
For x = 1 To i
For y = x To i
' TextWindow.WriteLine("x = Cateto Adyacente = " + x)
' TextWindow.WriteLine("y = Cateto Opuesto = " + y)
h = Math.SquareRoot(x*x+y*y)
HparteEntera = Math.Floor(h)
' TextWindow.WriteLine("h = Hipotenusa = " + h)
' Evaluación: Que el Triángulo sea Pitagórico y no sea Múltiplo de otro
Zafiro = 0
For j = 2 To i
' TextWindow.WriteLine(" j = Posible Factor Común = " + j)
Albis = 0
If HparteEntera <> h Then
j = i
EndIf
xj = x/j
XJparteEntera = Math.Floor(xj)
If XJparteEntera = xj Then
Albis = Albis + 1
EndIf
yj = y/j
YJparteEntera = Math.Floor(yj)
If YJparteEntera = yj Then
Albis = Albis + 1
EndIf
hj = h/j
HJparteEntera = Math.Floor(hj)
If HJparteEntera = hj Then
Albis = Albis + 1
EndIf
' TextWindow.WriteLine(" Albis = " + Albis)
If Albis = 3 Then
Zafiro = 1
EndIf
EndFor
If Zafiro = 0 And HparteEntera = h Then
n = n + 1