Print the factorial of a given number?
write a program to print the factorial of a given number?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Posted Nov 10, 2013, 11:24 PM EST
{
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();
}
Abhay ShankerRank #375 · 6.7K reputationPosted Nov 11, 2013, 1:35 AM EST
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 11, 2013, 5:49 AM EST
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));
}
}