Coprimes: Difference between revisions

Content added Content deleted
(Add APL)
(Add Cowgol)
Line 120: Line 120:
{{Out}}
{{Out}}
<pre>{{17, 23}, {18, 29}}</pre>
<pre>{{17, 23}, {18, 29}}</pre>

=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";

sub gcd(a: uint8, b: uint8): (r: uint8) is
while b != 0 loop
r := a;
a := b;
b := r % b;
end loop;
r := a;
end sub;

record Pair is
x: uint8;
y: uint8;
end record;

sub printPair(p: [Pair]) is
print_i8(p.x);
print_char(' ');
print_i8(p.y);
print_nl();
end sub;

var pairs: Pair[] := {
{21,15}, {17,23}, {36,12}, {18,29}, {60,15}
};

var i: @indexof pairs := 0;
while i < @sizeof pairs loop
if gcd(pairs[i].x, pairs[i].y) == 1 then
printPair(&pairs[i]);
end if;
i := i + 1;
end loop;</lang>


=={{header|Factor}}==
=={{header|Factor}}==