This is simple program to calculate factorial number of a given number using recursion functions. This program is full written in C# and supported by every version. You can also use loops instead of recursion functions to calculate factorial number.
Please feel free to contact us if you feel any problem while implementing recursion logic.
Source Code:
using System;
using System.Text;
using System.Collections;
using System.Data;
namespace Console_App
{
public class clsFactorial
{
public static void Main()
{
try
{
Console.WriteLine("The factorial of 6 is: {0}\n",
Factorial(6));
}
catch(Exception ex)
{
//handle exception here
}
Console.ReadLine();
}
static long Factorial(long number)
{
if (number <= 1)
return 1;
else
return number * Factorial(number - 1);
}
}
}
4 comments: