//Usings.
using System
/// <summary>
/// Calcula el factorial de un número entero no negativo.
/// </summary>
/// <param name="number">El número entero no negativo.</param>
/// <returns>El factorial del número.</returns>
public static int Factorial(int number)
{
if (number < 0)
{
throw new ArgumentException("El número debe ser no negativo.", nameof(number));
}
int result = 1;
for (int i = 2; i <= number; i++)
{
result *= i;
}
return result;
}
C#: Calcular el factorial de un número entero no negativo
Tiempo de lectura: < 1 minuto