Coprimes: Difference between revisions
Content added Content deleted
m (fix) |
Catskill549 (talk | contribs) (added AWK) |
||
Line 277: | Line 277: | ||
{{Out}} |
{{Out}} |
||
<pre>{{17, 23}, {18, 29}}</pre> |
<pre>{{17, 23}, {18, 29}}</pre> |
||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f COPRIMES.AWK |
|||
BEGIN { |
|||
n = split("21,15;17,23;36,12;18,29;60,15",arr1,";") |
|||
for (i=1; i<=n; i++) { |
|||
split(arr1[i],arr2,",") |
|||
a = arr2[1] |
|||
b = arr2[2] |
|||
if (gcd(a,b) == 1) { |
|||
printf("%d %d\n",a,b) |
|||
} |
|||
} |
|||
exit(0) |
|||
} |
|||
function gcd(p,q) { |
|||
return(q?gcd(q,(p%q)):p) |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
17 23 |
|||
18 29 |
|||
</pre> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |