->Write a program to find the factorial of input the given number Using Recursion method ?
class Program
{
static void Main(string[] args)
{ int n,fact;
Console.WriteLine("Enter the value");
n = int.Parse(Console.ReadLine());
fact = factorial(n);
Console.WriteLine("factorial number is: {0}",fact);
Console.ReadLine();
} static int factorial(int n)
{
if (n == 1)
return n;
else
return n *factorial(n - 1);
}
}
class Program
{
static void Main(string[] args)
{ int n,fact;
Console.WriteLine("Enter the value");
n = int.Parse(Console.ReadLine());
fact = factorial(n);
Console.WriteLine("factorial number is: {0}",fact);
Console.ReadLine();
} static int factorial(int n)
{
if (n == 1)
return n;
else
return n *factorial(n - 1);
}
}
No comments:
Post a Comment