Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace exe._03
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Digite um número para fazer o fatorial:");
- int n = Convert.ToInt32(Console.ReadLine());
- int[] f = new int[n];
- int rf = 1;
- int v = 1;
- //Montando o Array
- for (int i = 0; i <= (n - 1); i++)
- {
- if (i == 0)
- {
- f[i] = n;
- }
- else
- {
- f[i] = n - v;
- v++;
- }
- }
- //Fatorial
- foreach (var x in f)
- {
- rf *= x;
- }
- Console.WriteLine("\nO resultado do fatorial é: {0}", rf);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment