Wednesday, February 16, 2011

Factorial Program

Factorial Program
Lets make a factorial program using FOR loop. First of all we should understand what's the mechanism of factorial. Factorial number are those number which multiply themselves by its lower number. If you want to find out factorial of 4 that will be ( 4 x 3 x 2 x 1 ) 24.



static void Main(string[] args)
        {
            int num;
            int result=1;
            Console.WriteLine("Enter Any Number To Find its Factorial");
            num = Convert.ToInt32(Console.ReadLine());
            for (int i = num; i > 1 ; i--)
                result *= i;
            Console.WriteLine("Factorial of "+ num +" is " + result);
            Console.ReadKey();
            
        }

No comments:

Post a Comment