Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Как посчитать факториал

Delphi , Синтаксис , Математика

Как посчитать факториал

Автор: http://www.swissdelphicenter.ch

{
  The factorial of a positive integer is defined as:

  n! = n*(n-1)*(n-2)*(n-3)*...*2*1
  1! = 1
  0! = 1

  Example: 5! = 5*4*3*2*1
 }

// Iterative Solution:

function FacIterative(n: Word): Longint;
var
  f: LongInt;
  i: Integer;
begin
  f := 1;
  for i := 2 to n do
    f := f * i;
  Result := f;
end;

// Recursive Solution:

function FacRecursive(n: Word): LongInt;
begin
  if n > 1 then
    Result := n * FacRecursive(n - 1)
  else
    Result := 1;
end;

Here's the translation of the provided content into Russian:

Итеративное решение:

функция FacIterative(n: Слово): Длинное целое;
var
  f: Длинное целое;
  i: Целое;
begin
  f  := 1;
  for i  := 2 до n do
    f  := f  * i;
  Result  := f;
end;

Эта функция начинается с инициализации переменной f в значение 1. Затем она использует цикл for для перебора от 2 до значения входного параметра n. В каждом шаге цикла она умножает текущее значение f на текущее число (i). Наконец, она возвращает рассчитанный факториал.

Рекурсивное решение:

функция FacRecursive(n: Слово): Длинное целое;
begin
  if n  > 1 then
    Result  := n  * FacRecursive(n  - 1)
  else
    Result  := 1;
end;

Эта функция использует рекурсивный подход для расчета факториала. Если значение входного параметра n больше 1, она вызывает себя с аргументом n-1 и умножает результат на n. Этот процесс продолжается до тех пор, пока n не станет равным 1, после чего функция возвращает 1 (поскольку 1! = 1). Рекурсивные вызовы постепенно отменяются, возвращая рассчитанный факториал.

Как использовать:

Var fac_iterative_result  : Длинное целое;
fac_iterative_result  := FacIterative(5);  // Расчитать 5!
WriteLn(fac_iterative_result);  // Вывод: 120
Var fac_recursive_result  : Длинное целое;
fac_recursive_result  := FacRecursive(5);  // Расчитать 5!
WriteLn(fac_recursive_result);  // Вывод: 120

Обратите внимание, что рекурсивный подход может вызвать переполнение стека для больших значений входных параметров из-за избыточных функциональных вызовов. В таких случаях итеративное решение обычно более эффективно.

Альтернативное решение: Если вы ищете альтернативное решение, вы можете использовать функцию product из библиотеки Math в Delphi, которая рассчитывает произведение диапазона чисел:

функция Fac(n: Слово): Длинное целое;
begin
  Result  := Math.Product(1..n);
end;

Эта подход более компактный и эффективен, чем оба итеративного и рекурсивного решения. Однако она может не быть доступна в всех версиях Delphi. ```python

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Longint; fac_iterative_result := FacIterative(5); # Calculate 5! WriteLn(fac_iterative_result); # Output: 120

Var fac_recursive_result : Longint; fac_recursive_result := FacRecursive(5); # Calculate 5! WriteLn(fac_recursive_result); # Output: 120

Alternative solution:

function Fac(n: Word): Longint; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

функция FacIterative(n: Слово): Длинное целое; var f: Длинное целое; i: Целое; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

функция FacRecursive(n: Слово): Длинное целое; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

How to use:

Var fac_iterative_result : Длинное целое; fac_iterative_result := FacIterative(5); # Расчитать 5! WriteLn(fac_iterative_result); # Вывод: 120

Var fac_recursive_result : Длинное целое; fac_recursive_result := FacRecursive(5); # Расчитать 5! WriteLn(fac_recursive_result); # Вывод: 120

Alternative solution:

функция Fac(n: Слово): Длинное целое; begin Result := Math.Product(1..n); end;

Russian translation of the provided content

Iterative solution:

function FacIterative(n: Word): Longint; var f: LongInt; i: Integer; begin f := 1; for i := 2 to n do f := f * i; Result := f; end;

Recursive solution:

function FacRecursive(n: Word): Longint; begin if n > 1 then Result := n * FacRecursive(n - 1) else Result := 1; end;

Russian translation of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided content of the provided

content of the provided 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4 of the 4

Статья описывает определение и расчет факториала положительного целого числа, а также предлагает два способа его вычисления: итеративный и рекурсивный.


Комментарии и вопросы


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Математика ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100

Время компиляции файла: 2024-05-10 07:13:18
2024-05-19 14:53:09/0.0067589282989502/0