Я работал над калькулятором для биномиального распределения, где факториалы являются неотъемлемой частью уравнения. Моя проблема в том, что всякий раз, когда входное значение больше 12, результат неверен. Мой код здесь:
using System;
namespace StringLength {
public static class MainClass {
public static void Main(string[] args) {
var loop = 1;
while (loop == 1) {
int input, result = 0, a, b;
Console.Write("Enter a positive integer: ");
input = Int32.Parse(Console.ReadLine());
// Factorials of both 0 and 1 are equal to one
if (input == 0 || input == 1)
{
result = 1;
}
else {
// Sets variable a to be equal to input and b to be 1 number lower than a
a = input;
b = a - 1;
// Calculates the factorial
result = a * b;
Console.WriteLine("{0}, {1}", b, result);
while (b != 1) {
b -= 1;
result *= b;
Console.WriteLine("{0}, {1}", b, result);
}
}
}
}
}
}