Hello, I need to learn how can I find factorial of a particular number in C#?

For instance, "four factorial": "4!" means 1×2×3×4 = 24.

asked in C# category

The best option is to use the for loop:

```using System;

class FindFactorial
{
static void Main()
{
int n = int.Parse(Console.ReadLine());

int factorial = 1;
for (int i = 1; i <= n; i++)
{
factorial *= i;
}

Console.WriteLine(factorial);
}
}
```

edited by user golearnweb

THIS IS HOW TO FIND FACTORIAL WITH WHILE LOOP:

```using System;

class FindFactorialWhileLoop
{
static void Main()
{
{
Console.Write("Enter your factorial number = ");
decimal n = decimal.Parse(Console.ReadLine());
decimal result = 1;

while (true)
{
Console.Write(n);
if (n == 1)
{
break;
}
Console.Write(" * ");
result *= n;
n--;
}
Console.WriteLine(" = {0}", result);
}
}
}```

edited by user golearnweb

Here is with the do-while loop:

```using System;

class FindFactorialDoWhileLoop
{
static void Main()
{
int n = int.Parse(Console.ReadLine());

int factorial = 1;

do
{
factorial *= n;
n--;
} while (n > 0);
Console.WriteLine("n! = {0}", factorial);
}
}```