I have written a simple loop to get a factorial.However, the code seem to be neglecting the condition(n>=1) and i end u with zero as the n!.
The code works when i use (n >= 2) as opposed to (n >= 1).
class Program
{
static void Main(string[] args)
{
int n;
n = int.Parse(Console.ReadLine());
decimal factorial = 1;
Console.Write(" {0} * ", n);
do
{
n--;
factorial *= n;
Console.Write(" * " + n);
} while (n != 1);
Console.WriteLine("=" + factorial);
}
}
If i put n = 10, i expect to get 10*9*8*7*6*5*4*3*2*1 = 3628800 instead, i get, 10*9*8*7*6*5*4*3*2*1*0 = 0