How to calculate factorial with single line of code in C#

using System;
using System.Linq;
using System.Numerics;

public static class Factorial
{
    public static void Main(string[] args)
    {
        int num = 100;
        Console.WriteLine(Enumerable.Range(1, num).Select(i => new BigInteger(i)).Aggregate((a, b) => a * b));
    }
}
// 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

Leave a Reply

Your email address will not be published. Required fields are marked *