C# Program to find factorial of a number


In this program, You will learn how to find factorial of a number in C#.


4! = 1 * 2 * 3 * 4 => 24

Example: How to find factorial of a number in C#.

using System;
public class Program
{
	public static void Main(string[] args)
	{
		int n, i, f = 1;
		Console.Write("Enter a number:");
		n = Convert.ToInt32(Console.ReadLine());

		for (i = 1; i <= n; i++)
		{
			f = f * i;
		}

		Console.WriteLine("Factorial is:" + f);
	}
}

Output:

Enter a number:5
Factorial is:120