Generate Factorial number in C#

Program to generate factorial number.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


namespace Test_Application
{   
    class Program
    {
        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(fact);
            Console.ReadLine();
        }
    }
}

Output:-  Enter the number   6
               is   720                                 Format     // 6*5*4*3*2*1 

Share this

Previous
Next Post »