Factorial in C Sharp


For a number n, the product of all its positive descending integers is called it’s factorial which is denoted by n! and is pronounced as “n factorial”, it is also called “n bang” or “n shriek”. In Combinations and Permutations in mathematics, the factorial of a number is used.

For example:

5! = 5*4*3*2*1 = 120


using System;  
  public class Example  
     public static void Main(string[] args)  
       int i, x=1, n;      
       Console.Write("Enter a Number: ");      
       n = int.Parse(Console.ReadLine());     
       for(i=1; i<=n; i++){      
        x = x*i;      
       Console.Write(n +"! = "+ x);    



In the above example, we are printing a factorial of a number in C# using for loop.

Please Share