Greatest common divisor: Difference between revisions

Content added Content deleted
m (→‎{{header|Simula}}: Fixed {{out}})
m (→‎{{header|AWK}}: portability)
Line 299: Line 299:
=={{header|AWK}}==
=={{header|AWK}}==
The following scriptlet defines the gcd() function, then reads pairs of numbers from stdin, and reports their gcd on stdout.
The following scriptlet defines the gcd() function, then reads pairs of numbers from stdin, and reports their gcd on stdout.
<lang awk>$ awk 'func gcd(p,q){return(q?gcd(q,(p%q)):p)}{print gcd($1,$2)}'
<lang awk>$ awk 'function gcd(p,q){return(q?gcd(q,(p%q)):p)}{print gcd($1,$2)}'
12 16
12 16
4
4
Line 306: Line 306:
45 67
45 67
1</lang>
1</lang>



=={{header|Axe}}==
=={{header|Axe}}==