C# Program to Find Factorial of Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using System; namespace FactorialOfNumber { class Program { static void Main(string[] args) { int num, i, fact = 1; //clrscr(); Console.WriteLine("\n >>C# PROGRAM TO FIND FACTORIAL OF GIVEN NUMBER <<\n"); Console.Write("\n Enter the Number whose Factorial you want: "); num=Convert.ToInt32(Console.ReadLine()); for (i = num; i >= 2; i--) //i is intializing with num value and is decremented till 2 { fact = fact * i; //fact is updating with changing value of i } Console.WriteLine("\n The factorial of {0} is {1}.\n\n", num, fact); Console.ReadLine(); } } } |
For C Program : C Program to find the Factorial of Given Number