class Program
{
static int Factorial(int n)
{
if (n <= 1)
return 1;
int fact = 1;
for (int i = 2; i <= n; i++)
{
fact = fact * i;
}
return fact;
}
static void Main(string[] args)
{
Console.Write("Enter a Number to find factorial: ");
int n = Convert.ToInt32(Console.ReadLine());
int r = Factorial(n);
Console.WriteLine(n.ToString() + "! = " + r.ToString());
Console.ReadLine();
}
}
}
{
static int Factorial(int n)
{
if (n <= 1)
return 1;
int fact = 1;
for (int i = 2; i <= n; i++)
{
fact = fact * i;
}
return fact;
}
static void Main(string[] args)
{
Console.Write("Enter a Number to find factorial: ");
int n = Convert.ToInt32(Console.ReadLine());
int r = Factorial(n);
Console.WriteLine(n.ToString() + "! = " + r.ToString());
Console.ReadLine();
}
}
}
OUTPUT
CLICK TO DOWNLOAD
No comments:
Post a Comment