How can I calculate a factorial in C# using a library call?

后端 未结 6 1404
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 10:29

I need to calculate the factorial of numbers up to around 100! in order to determine if a series of coin flip-style data is random, as per this Wikipedia entry on Bayesian p

6条回答
  •  感情败类
    2021-01-05 11:19

    using System;
    //calculating factorial with recursion
    namespace ConsoleApplication2
    {
        class Program
        {
            long fun(long a)
            {
                if (a <= 1)
                {
                    return 1;}
                else
                {
                    long c = a * fun(a - 1);
                    return c;
                }}
    
            static void Main(string[] args)
            {
    
                Console.WriteLine("enter the number");
                long num = Convert.ToInt64(Console.ReadLine());
                Console.WriteLine(new Program().fun(num));
                Console.ReadLine();
            }
        }
    }
    

提交回复
热议问题