Advertisement
n128

Cálculo Factorial

Nov 28th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 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 CalculoFactorial
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Introduce un número para calcular su factorial: ");
  14.             int num = Convert.ToInt32(Console.ReadLine());
  15.  
  16.             int resultado = 1;
  17.  
  18.             for(int contador = 1; contador < num + 1; contador++)
  19.             {
  20.                 // resultado = resultado * contador;
  21.                 resultado *= contador;
  22.             }
  23.  
  24.             Console.WriteLine(Environment.NewLine + "El factorial de " + num + " es " + resultado);
  25.  
  26.             Console.ReadKey();
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement