Introduction
In this blog, we will write a C# program to user-define a factorial number.
User-Define Factorial number in C#
This code sample shows you how to user-define a factorial number in C#:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace UserDefineFactorialNumber {
- class Program {
- static void Main(string[] args) {
- int a = 1, Fact = 1;
- int Num = 5;
- while (a <= Num) {
- Fact = Fact * a;
- a++;
- Console.WriteLine("The Factorial Number is " + Fact);
- }
- Console.ReadLine();
- }
- }
- }
Now run the user-defined factorial number code
Click on the Start button:
Output of the code:
I hope you understood how to user-define a factorial number using C# code.