Here's how to find the factorial of 3.
Mathematically it follows like this
3*2*1=6
class FactorialProgram
{
static void Main(string[] args)
{
var fp = new FactorialProgram();
Console.Write("\n Enter the number:\t");
var result = fp.fact(int.Parse(Console.ReadLine()));
Console.WriteLine(result);
Console.ReadLine();
}
int fact(int num)
{
int temp = 1;
for (int i = num; i > 1; i--)
{
temp = temp * i;
}
return temp;
}
}
|
Comments
Post a Comment