How to find the factorial of a number using c#
There are two approaches you can try for the above scenario one is with recursion and another one is using for loop.
static void Main(string[] args)
{
int rslt= FactorialWithoutR(5);
Console.WriteLine("Factorial is :{0}", rslt);
}
public static int Factorial(int limit)
{
// Using Recursion
if (limit == 0)
{
return 1;
}
return limit * Factorial(limit - 1);
}
public static int FactorialWithoutR(int limit)
{
int factorial = 1;
for (int i = 1; i <= limit; i++)
{
factorial = factorial * i;
}
return factorial;
}
0 comments: