Saturday 16 April 2016

Design a Console Application for generating Factorial of a no. using Recursion Method.

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

namespace ConsoleApplication16
{
    class Program
    {
        private static long Factorial(int n)
        {
            if (n == 0)
            {
                return 1;
            }
            return n * Factorial(n - 1);
        }
        static void Main(string[] args)
        {
            int a;
            Console.WriteLine("Enter a number");
            a = int.Parse(Console.ReadLine());
            long fact = Factorial(a);
            Console.WriteLine("{0} factorial is {1}", a, fact);
            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment