Monday, November 11, 2013

One liner Factorial calculating program using recursion in C#


using System;
 
public class Program
{
    //Using recursion
    static long Factorial(long number)
    {
        return ((number <= 1) ? 1 : number * Factorial(number - 1));
    }
 
    static void Main(string[] args)
    {
        long numToFindFact = 6;
        Console.WriteLine("The factorial of " + numToFindFact  + " is: {0}\n", Factorial(numToFindFact));
    }
}

No comments:

Post a Comment