“Trouvez une factorielle d'un nombre” Réponses codées

Factoriel

// Factorialize a Number

function factorialize(num) {
	if (num === 0) return 1;
	return num * factorialize(num - 1);
}

factorialize(5);

// OR with Tail Call Optimization (https://stackoverflow.com/questions/33923/what-is-tail-recursion)

function factorialize(num, factorial = 1) {
	if (num == 0) {
		return factorial;
	} else {
		return factorialize(num - 1, factorial * num);
	}
}

factorialize(5);
YosKa

factoriel du nombre

        public static void Factorial(int n)
        {
            var number = new int[999999];
            number[0] = 1;
            int numLength = 1;
            for (int times = 2; times <= n; times++)
                numLength = Multiply(times, number,numLength);

            for (int i = numLength - 1; i >= 0; i--)
                Console.Write(number[i]);
        }

        
        static int Multiply(int times, int[] number,int numLength)
        {
            int carry = 0; 
            for (int i = 0; i < numLength; i++)
            {
                int product = number[i] * times + carry;
                number[i] = product % 10;
                carry = product / 10;
            }

            while (carry != 0)
            {
                number[numLength] = carry % 10;
                carry /= 10;
                numLength++;
            }
            return numLength;
        }
PrashantUnity

Factoriel

function factorialize(num) {
  for (var product = 1; num > 0; num--) {
    product *= num;
  }
  return product;
}

factorialize(5);
Mysterious Monkey

Trouvez une factorielle d'un nombre

<?php
              
      $num = 3;
      $factorial = 1;
      if($num != 0) {
        for($i = $num; $i>=1; $i--) {
          $factorial = $factorial * $i;
        }
      }
      else {
        $factorial = 1;
      }
      echo "Factorial of $num is $factorial";

    ?>
Outrageous Ostrich

Réponses similaires à “Trouvez une factorielle d'un nombre”

Questions similaires à “Trouvez une factorielle d'un nombre”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code