Factorial Program In C#

Factorial Program in C#: The factorial of a number is calculated as the product of all positive integers descending from that number to 1. This mathematical operation is represented by the notation n!. An illustration of this concept is given below:

Example

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

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

Here, the mathematical expression 4! is spoken as "4 factorial", it is also known as "4 bang" or "4 shriek".

The factorial function is typically utilized in Combinations and Permutations within the field of mathematics.

Let's explore the factorial program in C# utilizing a for loop.

Example

Example

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);  

     }

  }

Output:

Output

Enter any Number: 6

Factorial of 6 is: 720

Input Required

This code uses input(). Please provide values below: