Реализации алгоритмов/Факториал: различия между версиями

Содержимое удалено Содержимое добавлено
Swift
Строка 165:
=== Ada ===
<source lang="ada">
subtype Natural is Integer range 0 .. Integer'Last;
with Ada.Text_IO, Ada.Integer_Text_IO; use Ada;
procedurefunction Factorial (N: Natural) return Natural is
begin
if N = 0 then
declare
function Factorial (N: Integer) return Integer is1;
beginelse
return N * if Factorial(N=0 then- 1);
end return 1if;
end Factorial;
else
</source>
return N*Factorial(N-1);
или используя «if expression» (Ada 2012)
end if;
<source lang="ada">
end Factorial;
subtype Natural is Integer range 0 .. Integer'Last;
begin
function Factorial (N: Natural) return Natural is
Text_IO.Put ("10! = ");
begin
Integer_Text_IO.Put (Factorial(10)); Text_IO.New_Line;
return (if N = 0 then 1 returnelse N * Factorial(N - 1));
end;
end Factorial;
</source>