In this article, you’ll learn to find the factorial of a number and display it.
The factorial of a number is the product of all the integers from 1 to that number.
For example, the factorial of 6 (denoted as 5!) is 1*2*3*4*5 = 120. Factorial is not defined for negative numbers and the factorial of zero is one, 0! = 1.
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
static void Main(string[] args) { int i, number, fact; Console.WriteLine("Enter the Number"); number = int.Parse(Console.ReadLine()); fact = number; for (i = number - 1; i >= 1; i--) { fact = fact * i; } Console.WriteLine("\nFactorial of Given Number is: "+fact); Console.ReadLine(); } |
Output: