Pythagorean triples: Difference between revisions

Content added Content deleted
m (language name corrected)
(Second PL/I version included)
Line 1,924: Line 1,924:


=={{header|PL/I}}==
=={{header|PL/I}}==
Version 1
<lang PL/I>*process source attributes xref or(!);
<lang PL/I>*process source attributes xref or(!);
/*********************************************************************
/*********************************************************************
Line 2,014: Line 2,015:


End;</lang>
End;</lang>
Version 2
<lang PL/I>
pythagorean: procedure options (main, reorder); /* 23 January 2014 */
declare (a, b, c) fixed (3);
declare (asquared, bsquared) fixed;
declare (triples, primitives) fixed binary(31) initial (0);

do a = 1 to 100;
asquared = a*a;
do b = a+1 to 100;
bsquared = b*b;
do c = b+1 to 100;
if a+b+c <= 100 then
if asquared + bsquared = c*c then
do;
triples = triples + 1;
if GCD(a,b) = 1 then primitives = primitives + 1;
end;
end;
end;
end;
put skip data (triples, primitives);


GCD: procedure (a, b) returns (fixed binary (31)) recursive;
declare (a, b) fixed binary (31);

if b = 0 then return (a);

return (GCD (b, mod(a, b)) );

end GCD;

end pythagorean;</lang>
Output:
<pre>
TRIPLES= 17 PRIMITIVES= 7;
</pre>
Output for P=1000:
<pre>
TRIPLES= 325 PRIMITIVES= 70;
</pre>


=={{header|PureBasic}}==
=={{header|PureBasic}}==