Question about factorial in C #

2

I'm trying to solve this repetition exercise:

  

Make sure that you start a variable n (number) as 1 and a factorial   (result) as 1 and varies from 1 to 10.

Code:

int fatorial = 1;
for (int n = 1; n <= 10; n++)
{

}

I can not do it at all. I've tried it in many ways, but I always find it difficult to get the factorial of all numbers with just a looping. can anybody help me? : D

    
asked by anonymous 15.06.2016 / 21:36

1 answer

2
int fatorial = 1;
for (int n = 1; n <= 10; n++)
{
    fatorial*=n;
    Console.WriteLine(n+" fatorial= "+fatorial);
}

1 factorial = 1

2 factorial = 2

3 factorial = 6

4 factorial = 24

5 factorial = 120

6 factorial = 720

7 factorial = 5040

8 factorial = 40320

9 factorial = 362880

10 factorial = 3628800

    
15.06.2016 / 22:14