Static Function And Factorial



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

namespace staticFactorial
{
    public static class fact
    {
        

        public static long method(long factorial)
        {
          
           
                if (factorial > 1)
                {
                    return factorial * method(factorial - 1);
                }

                else
                {
                    return 1;
                }
               


        }
    }
    class Program
    {

        static void Main(string[] args)
        {

           
            Console.WriteLine("Enter Any Number : ");
            long factorial = Convert.ToInt32(Console.ReadLine());
            long x = fact.method(factorial);
            Console.WriteLine("factorial is : {0} ", x);
            Console.ReadLine();
          
          
        }

No comments:

Post a Comment