Sunday, July 1, 2012

factorial number c#


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

namespace factorial
{
    class Program
    {
        static void Main(string[] args)
        {
         
            int fact = 1, i,n;
            Console.WriteLine("Enter any no. for factorial");
            n = int.Parse(Console.ReadLine());
            for (i = n; i >= 1; i--)
            {
                fact = fact * i;
            }

            Console.WriteLine("factorial value is:"+fact);
            Console.ReadKey();      
         }
    }
}

output

Enter any no. for factorial
7
factorial value is:5040

1 comment: