Doubt about factorial in C#

Asked

Viewed 4,967 times

2

I’m trying to solve this repetition exercise:

Make a go of starting a variable n (number) as 1 and factorial (result) as 1 and ranges n from 1 to 10.

Code:

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

}

I can’t do it at all. I’ve tried it in several ways, but I always stop at the moment to get the factorial of all numbers with just one looping. Could someone help me? D

  • https://pt.wikipedia.org/wiki/Fatorial http://www.matematicadidatica.com.br/Fatorial.aspx, q you tried?

  • I did not understand very well the statement. You are with difficulty in making the factorization is this?

  • Pardon, error in the statement. It was not factorization, but factorial XD. But I already managed to solve, thanks for the help.

  • @Gabrieliasi the "solved" of the site is you accept a response, as you have already done. This already points out that the question problem has been solved :) Neither need add in the title, the site works different from forums.

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

  • Wow! That simple, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.