Latest Post

Sunday, 1 January 2017

How to find the factorial of a given number [C#]

Write a program in C# to find the factorial of a given number.

Following is the simple C# code :

class Lab
    {
        static void Main(string[] args)
        {
            int i, number, fact;
            Console.Write("\n Enter the Number whose Factorial you want: ");
            number = Convert.ToInt32(Console.ReadLine());
            fact = number;
            for (i = number - 1; i >= 1; i--)
            {
                fact = fact * i;
            }
            Console.WriteLine("\n The factorial of {0} is {1}.\n\n", number, fact);
            Console.ReadLine();  
        }
    }

Output:-


Government Jobs