Рекурсия

long fact(long n)
{
  if (n <= 1)
    return 1;
  else
    return n * fact(n - 1);
}
#define fact(n) _fact(n, 1)

long _fact(long n, long acc)
{
  if (n <= 1)
    return acc;
  else
    return _fact(n-1, n*acc);
}

results matching ""

    No results matching ""