Special pythagorean triplet: Difference between revisions

m
→‎{{header|ALGOL 68}}: Remove test for solution found
(→‎{{header|PL/M}}: Remove redundant test and slight simplification)
m (→‎{{header|ALGOL 68}}: Remove test for solution found)
Line 11:
# a + b + c = 1000, a2 + b2 = c2, a < b < c #
INT sqrt 1000 = ENTIER sqrt( 1000 );
BOOLFOR foundn TO sqrt 1000 :=OVER FALSE;2 DO
FOR n TO sqrt 1000FOR OVERm 2FROM WHILEn NOT+ found1 TO sqrt 1000 DO
FOR m FROM n + 1 TO sqrt 1000 WHILE NOT found DO
# a = m^2 - n^2, b = 2mn, c = m^2 + n^2 ( Euclid's formula ), so #
# a + b + c = m^2 - n^2 + 2mn + m^2 + n^2 = 2( m^2 + mn ) = 2m( m + n ) #
Line 22 ⟶ 21:
INT c = m2 + n2;
print( ( "a = ", whole( a, 0 ), ", b = ", whole( b, 0 ), ", c = ", whole( c, 0 ), newline ) );
print( ( "a * b * c = ", whole( a * b * c, 0 ), newline ) );
found := TRUE
FI
OD
3,032

edits