Pages

Saturday, March 30, 2013

How to write C# program to find the factorial of number


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int number, i,factorial=1;

            Console.WriteLine("Enter the an integer number");

            number =Convert.ToInt32(Console.ReadLine());

            for (i = 1; i <= number; i++)
            {
                factorial = factorial * i;                          
            }

            Console.WriteLine("Factorial is");
            Console.WriteLine(factorial);
            Console.ReadKey();
        }
    }
}

1 comment: