Advertisement
NameL3ss

appFactorial

Aug 14th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. Clase Factorial:
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace appFactorial.Clases
  9. {
  10. class Factorial
  11. {
  12. double numero;
  13. double resultado = 1;
  14.  
  15. public Factorial()//constructor sin parametros
  16. {
  17.  
  18. }
  19.  
  20. //metodo setter y getter para el atributo numero
  21. public double Numero
  22. {
  23. set { numero = value; }
  24. get { return numero;}
  25. }
  26.  
  27. /// <summary>
  28. /// metodo para calcular el factorial
  29. /// </summary>
  30. public void Operacion()
  31. {
  32. int i;
  33. for( i = 1; i <= numero; i++){
  34.  
  35. resultado = resultado * i;
  36.  
  37. }
  38. Console.Write("el factorial de " + numero + " es : " + resultado);
  39. }
  40. }
  41. }
  42.  
  43.  
  44.  
  45. Clase main:
  46.  
  47. using appFactorial.Clases;
  48. using System;
  49. using System.Collections.Generic;
  50. using System.Linq;
  51. using System.Text;
  52. using System.Threading.Tasks;
  53.  
  54. namespace appFactorial
  55. {
  56. class Program
  57. {
  58. static void Main(string[] args)
  59. {
  60.  
  61.  
  62.  
  63. Factorial a = new Factorial();//instancia del Objeto Factorial
  64. Console.Write("*****ingrese un numero : *****\n");
  65. try {
  66.  
  67. a.Numero = int.Parse(Console.ReadLine());
  68. a.Operacion();
  69. Console.Write("\npulse una tecla para continuar...");
  70. Console.ReadKey();
  71.  
  72.  
  73. }
  74.  
  75. catch(Exception n)
  76. {
  77. Console.Write("error\n"+n.Message);
  78. Console.ReadKey();
  79.  
  80. }
  81.  
  82.  
  83.  
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement