Guest User

Untitled

a guest
May 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace exe._03
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Digite um número para fazer o fatorial:");
  14. int n = Convert.ToInt32(Console.ReadLine());
  15. int[] f = new int[n];
  16. int rf = 1;
  17. int v = 1;
  18.  
  19. //Montando o Array
  20. for (int i = 0; i <= (n - 1); i++)
  21. {
  22. if (i == 0)
  23. {
  24. f[i] = n;
  25. }
  26. else
  27. {
  28. f[i] = n - v;
  29. v++;
  30. }
  31. }
  32.  
  33. //Fatorial
  34. foreach (var x in f)
  35. {
  36. rf *= x;
  37. }
  38.  
  39. Console.WriteLine("\nO resultado do fatorial é: {0}", rf);
  40. Console.ReadKey();
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment