Thursday, 15 October 2015

Find Factorial of Number in C#

using System;
class Program
{
    public static void Main()
    {
        int factor;
        Console.WriteLine("Enter a number");
        int number = int.Parse(Console.ReadLine());
        factor = number;
        for (int i = number - 1; i >= 1; i--)
        {
            factor = factor * i;
        }
        Console.WriteLine(factor);
    }
}

No comments:

Post a Comment