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
Program :
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 :
Enter any Number: 5
Factorial of 5 is: 120
Enter any Number: 6
Factorial of 6 is: 720