Home / Programs / C# Program - Factorial program
🚀 Programming Example

C# Program - Factorial program

👁 319 Views
💻 Practical Program
📘 Step Learning

Factorial Program in C#: Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!. For example:

4! = 4*3*2*1 = 24    
6! = 6*5*4*3*2*1 = 720      

Here, 4! is pronounced as "4 factorial", it is also called "4 bang" or "4 shriek".

The factorial is normally used in Combinations and Permutations (mathematics).

Let's see the factorial program in C# using for loop.

💻 Program Code

using System;  
  public class FactorialExample  
   {  
     public static void Main(string[] args)  
      {  
       int i,fact=1,number;      
       Console.Write("Enter any Number: ");      
       number= int.Parse(Console.ReadLine());     
       for(i=1;i<=number;i++){      
        fact=fact*i;      
       }      
       Console.Write("Factorial of " +number+" is: "+fact);    
     }  
  }  
                        

🖥 Program Output

Enter any Number: 6
Factorial of 6 is: 720
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.