Thursday 31 May 2012

Factorial of a number in C#



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

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, n, f;
            Console.WriteLine("enter the value of n");
            n = Convert.ToInt32(Console.ReadLine());
            f = n;
            for (i = n - 1; i >= 1; i--)
            {
                f = f * i;
            }
            Console.WriteLine("Factorial of given number is :" + f);
            Console.Read();
        }
    }
}

3 comments: