print the factorial of a given number?
write a program to print the factorial of a given number?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hemant SrivastavaPosted Nov 11, 2013, 10:49 AM
using System;
public class Program
{
//Using recursion
static long Factorial(long number)
{
return ((number <= 1) ? 1 : number * Factorial(number - 1));
}
static void Main(string[] args)
{
long numToFindFact = 6;
Console.WriteLine("The factorial of " + numToFindFact + " is: {0}\n", Factorial(numToFindFact));
}
}
Abhay ShankerPosted Nov 11, 2013, 6:35 AM
Posted Nov 11, 2013, 4:24 AM
{
console.WriteLine("please enter a number");
a=Convert.ToInt 32(console.ReadLine());
if(a==1) { Console.WriteLine(1);
}
else
{
b=(a-1)*a;
Console.WriteLine( b );
}
Console.ReadLine();
}