C# program to calculate factorial of n.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // ? 2017 TheFlyingKeyboard and released under MIT License // theflyingkeyboard.net namespace Factorial { class Program { static void Main(string[] args) { int n = 0; Console.Write("Enter number: "); n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Factorial of {0} is equal to {1}", n, factorial(n)); Console.ReadKey(); } public static int factorial(int n) { int fact = 1; for (int i = 2; i <= n; i++) { fact *= i; } return fact; } } }
C# Factorial