Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
28
Task/Least-common-multiple/Ada/least-common-multiple.ada
Normal file
28
Task/Least-common-multiple/Ada/least-common-multiple.ada
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Lcm_Test is
|
||||
function Gcd (A, B : Integer) return Integer is
|
||||
M : Integer := A;
|
||||
N : Integer := B;
|
||||
T : Integer;
|
||||
begin
|
||||
while N /= 0 loop
|
||||
T := M;
|
||||
M := N;
|
||||
N := T mod N;
|
||||
end loop;
|
||||
return M;
|
||||
end Gcd;
|
||||
|
||||
function Lcm (A, B : Integer) return Integer is
|
||||
begin
|
||||
if A = 0 or B = 0 then
|
||||
return 0;
|
||||
end if;
|
||||
return abs (A) * (abs (B) / Gcd (A, B));
|
||||
end Lcm;
|
||||
begin
|
||||
Put_Line ("LCM of 12, 18 is" & Integer'Image (Lcm (12, 18)));
|
||||
Put_Line ("LCM of -6, 14 is" & Integer'Image (Lcm (-6, 14)));
|
||||
Put_Line ("LCM of 35, 0 is" & Integer'Image (Lcm (35, 0)));
|
||||
end Lcm_Test;
|
||||
Loading…
Add table
Add a link
Reference in a new issue