Factorial Using Recursion
Let's start with Main Class
public static void Main(string[] args)
{
//Your code goes here
int i = 5;
Console.WriteLine("Recursive number of " + i + " is " + factorial(i));
}
Now we will create factorial function. Always start with the base condition, or when condition is stopped.
public static int factorial(int angka)
{
if(angka == 1)
{
return angka;
}
else
{
}
}
If the number not met with base condition, we will doing recursion.
public static int factorial(int angka)
{
if(angka == 1)
{
return angka;
}
else
{
return angka*(factorial(angka-1));
}
}