Greatest common divisor: Difference between revisions
Content added Content deleted
(Added solution in J.) |
(Ada example) |
||
Line 1: | Line 1: | ||
{{task}} |
{{task}} |
||
This task requires the finding of the greatest common divisor of two integers. |
This task requires the finding of the greatest common divisor of two integers. |
||
=={{header|Ada}}== |
|||
with Ada.Text_Io; use Ada.Text_Io; |
|||
procedure Gcd_Test is |
|||
function Gcd (A, B : Integer) return Integer is |
|||
begin |
|||
if A = 0 then |
|||
return B; |
|||
end if; |
|||
if B = 0 then |
|||
return A; |
|||
end if; |
|||
if A > B then |
|||
return Gcd(B, A mod B); |
|||
else |
|||
return Gcd(A, B mod A); |
|||
end if; |
|||
end Gcd; |
|||
begin |
|||
Put_Line("GCD of 100, 5 is" & Integer'Image(Gcd(100, 5))); |
|||
Put_Line("GCD of 5, 100 is" & Integer'Image(Gcd(5, 100))); |
|||
Put_Line("GCD of 7, 23 is" & Integer'Image(Gcd(7, 23))); |
|||
end Gcd_Test; |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
PROC gcd = (INT a, b) INT: ( |
PROC gcd = (INT a, b) INT: ( |