Calculates n factorial - CSharp System

CSharp examples for System:Math Geometry

Description

Calculates n factorial

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*ww  w.j av a 2 s . c om*/

public class Main{
        /// <summary>
        /// Calculates n factorial
        /// </summary>
        /// <param name="n"></param>
        /// <returns>int</returns>
        public static int Factorial(int n)
        {
            if (n <= 1)
                return 1;
            return n * Factorial(n - 1);
        }
}

Related Tutorials