E
E
Elia Fish2020-12-07 12:17:28
C++ / C#
Elia Fish, 2020-12-07 12:17:28

How is the factorial of a number obtained in a C# loop?

Hello gentlemen! Help me understand how it turns out for the for loop to calculate the factorial of the entered number, I understand that this formula produces a factorial, but how this happens, I can’t visualize the order of calculation.

int n = Convert.ToInt32(Console.ReadLine());
            int Foctarial = 1;
            for (int i = 2; i <= n; i++)
            {
                Foctarial *= i;
            }
            Console.WriteLine(Foctarial);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2020-12-07
@GavriKos

So what is there to visualize ... Let's say n is 5.
Build a table (just a table!) What is the Factorial variable at each iteration of the loop - i.e. starting from i==2 and ending with i==5.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question