-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
57 lines (50 loc) · 1.8 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _15_Fatorial
{
internal class Program
{
static void Main(string[] args)
{
/*
Programa para calcular e mostrar o fatorial de 0 até 10.
O programa deverá exibir cada número envolvido na multiplicação
de cada fatorial, conforme exemplo abaixo:
0! = 1
1! = 1
2! = 2 · 1 = 2
3! = 3 · 2 · 1 = 6
4! = 4 · 3 · 2 · 1 = 24
5! = 5 · 4 · 3 · 2 · 1 = 120
6! = 6 · 5 · 4 · 3 · 2 · 1 = 720
7! = 7 · 6 · 5 · 4 · 3 · 2 · 1 = 5040
8! = 8 · 7 · 6 · 5 · 4 · 3 · 2 · 1 = 40320
9! = 9 · 8 · 7 · 6 · 5 · 4 · 3 · 2 · 1 = 362880
10! = 10 · 9 · 8 · 7 · 6 · 5 · 4 · 3 · 2 · 1 = 3628800
*/
for (int numero = 0; numero <= 10; numero++)
{
int fatorial = 0;
Console.Write(numero + "! → " + (numero == 0 ? "1" : ""));
fatorial = numero;
for (int numeroAnterior = numero; numeroAnterior >= 1; numeroAnterior--)
{
Console.Write(numeroAnterior);
if (numeroAnterior != 1)
{
Console.Write(" · ");
fatorial = fatorial * (numeroAnterior - 1);
} else
{
Console.Write(" = " + fatorial);
}
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}