Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Factorial/Delphi/factorial-1.delphi
Normal file
16
Task/Factorial/Delphi/factorial-1.delphi
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
program Factorial1;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
function FactorialIterative(aNumber: Integer): Int64;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result := 1;
|
||||
for i := 1 to aNumber do
|
||||
Result := i * Result;
|
||||
end;
|
||||
|
||||
begin
|
||||
Writeln('5! = ', FactorialIterative(5));
|
||||
end.
|
||||
15
Task/Factorial/Delphi/factorial-2.delphi
Normal file
15
Task/Factorial/Delphi/factorial-2.delphi
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
program Factorial2;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
function FactorialRecursive(aNumber: Integer): Int64;
|
||||
begin
|
||||
if aNumber < 1 then
|
||||
Result := 1
|
||||
else
|
||||
Result := aNumber * FactorialRecursive(aNumber - 1);
|
||||
end;
|
||||
|
||||
begin
|
||||
Writeln('5! = ', FactorialRecursive(5));
|
||||
end.
|
||||
24
Task/Factorial/Delphi/factorial-3.delphi
Normal file
24
Task/Factorial/Delphi/factorial-3.delphi
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
program Factorial3;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
function FactorialTailRecursive(aNumber: Integer): Int64;
|
||||
|
||||
function FactorialHelper(aNumber: Integer; aAccumulator: Int64): Int64;
|
||||
begin
|
||||
if aNumber = 0 then
|
||||
Result := aAccumulator
|
||||
else
|
||||
Result := FactorialHelper(aNumber - 1, aNumber * aAccumulator);
|
||||
end;
|
||||
|
||||
begin
|
||||
if aNumber < 1 then
|
||||
Result := 1
|
||||
else
|
||||
Result := FactorialHelper(aNumber, 1);
|
||||
end;
|
||||
|
||||
begin
|
||||
Writeln('5! = ', FactorialTailRecursive(5));
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue