Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Clase Factorial:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace appFactorial.Clases
- {
- class Factorial
- {
- double numero;
- double resultado = 1;
- public Factorial()//constructor sin parametros
- {
- }
- //metodo setter y getter para el atributo numero
- public double Numero
- {
- set { numero = value; }
- get { return numero;}
- }
- /// <summary>
- /// metodo para calcular el factorial
- /// </summary>
- public void Operacion()
- {
- int i;
- for( i = 1; i <= numero; i++){
- resultado = resultado * i;
- }
- Console.Write("el factorial de " + numero + " es : " + resultado);
- }
- }
- }
- Clase main:
- using appFactorial.Clases;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace appFactorial
- {
- class Program
- {
- static void Main(string[] args)
- {
- Factorial a = new Factorial();//instancia del Objeto Factorial
- Console.Write("*****ingrese un numero : *****\n");
- try {
- a.Numero = int.Parse(Console.ReadLine());
- a.Operacion();
- Console.Write("\npulse una tecla para continuar...");
- Console.ReadKey();
- }
- catch(Exception n)
- {
- Console.Write("error\n"+n.Message);
- Console.ReadKey();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement