Special pythagorean triplet: Difference between revisions
Content deleted Content added
Realize in F# |
→{{header|ALGOL 68}}: Replaced with a solution using Euclid's formula, based on the XPL0 sample |
||
Line 7:
<br><br>
=={{header|ALGOL 68}}==
Using Euclid's formula, as in the XPL0 sample
...but doesn't stop on the first solution (thus verifying there is only one).
<lang algol68>BEGIN # find the product of the of the Pythagorian triplet a, b, c where:
# a + b + c = 1000, a2 + b2 = c2, a < b < c #
INT
FOR
FOR m FROM n + 1 TO
# 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 ) #
IF
print( ( "a = ", whole( a, 0 ), ", b = ", whole( b, 0 ), ", c = ", whole( c, 0 ), newline ) );
print( ( "a * b * c = ", whole( a * b * c, 0 ), newline ) )
FI
OD
OD
END
{{out}}
<pre>
a =
a * b * c = 31875000
</pre>
|