Author : Rahul
Write a program to print the factorial of the number
Program:
using System;
namespace ProgrammingQuestion
{
class Program
{
static void Main(string[] args)
{
//Variable Declaration
string enterVal;
int enterNum, factorial = 1;
//User Input
Console.Write("Enter Number:");
enterVal = Console.ReadLine();
enterNum = Convert.ToInt32(enterVal);
//Factorial Logic
for(int i=enterNum;i>0;i--)
{
factorial = factorial * i;
}
//Print Result
Console.WriteLine($"Factorial of the Number:{factorial}");
Console.Read();
}
}
}
Output:
Enter Number:5
Factorial of the Number:120