Loops Posted May 09, 2020

Factorial of a number n can be termed as multiplication of all numbers from 1 till the number n. n! = 1*2*3*...*n Example: 5!=1*2*3*4*5=120

```
public static double DoFactorial(long n)
{
// hardcode the simplest
// 0! = 1
// 1! = 1
// 2! = 2
if (n == 0)
{
return 1;
}
else if (n == 1)
{
return 1;
}
else if (n == 2)
{
return 2;
}
// n! = 1 * 2 * 3 * ... * n
double nFactorial = 1;
for (int i = 2; i <= n; i++)
{
nFactorial = nFactorial * i;
}
return nFactorial;
}
```

**How it works:**

```
for n=5
nFactorial = 1, n=5
i = 1 => nFactorial = 1 * 1 = 1
i = 2 => nFactorial = 1 * 2 = 2
i = 3 => nFactorial = 2 * 3 = 6
i = 4 => nFactorial = 6 * 4 = 24
i = 5 => nFactorial = 24 * 5 = 120
```

which is the expected result

Compute and generate a compressed string for a given string containing repetitions

Find all possible natural numbers below a given limit such that a3+b3 = c3+d3

Find all the pairs in a given ordered set of numbers whose sum is equal to a given input sum

Find all the pairs in a given unordered set of numbers whose sum is equal to a given input sum

Sort the given unordered set of Binary digits

Implementing Cookie Authentication in ASP.NET Core without Identity

Writing Docker Container Logs to MySQL using Fluentd

C# Fundamentals - Private Constructor and Static Constructor Explained

EF Core and LINQ - Client vs Server Evaluation and Immediate vs Deferred Execution Explained

Garbage Collection in .NET Core Explained - Concepts and Best Practices