C Sharp Program Factorial Method

By | August 20, 2023

C Sharp Program Factorial Method


using System;
namespace FactorialCalculator
{
    class Program
    {

        static long Factorial(int n)
        {

            long fact = 1;

            for (int i = 1; i <= n; i++)
            {
                fact = fact * i;
            }

            return fact;
        }
    
        static void Main(string[] args)
        {
            
            int n;
            Console.Write("Enter a number to find its factorial: ");
            
            n = int.Parse(Console.ReadLine());
            
            long result = Factorial(n);
            Console.WriteLine("Factorial="+result);
            Console.ReadKey();
         }
    
        

    }
}

Output:
C Sharp program to find factorial of a number using method

C Sharp program to find factorial of a number using method

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *