Programas en C#

Wednesday, October 18, 2006

5. Pedir dos números, transformarlos a enteros y dividirlos. Realizar gestión de excepciones

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

public static void Main(string[] args){

int i, j, k;

string temp1, temp2;

Console.WriteLine("Escriba el primer entero");

temp1 = Console.ReadLine();

Console.WriteLine("Escriba el segundo entero");

temp2 = Console.ReadLine();

try

{

i = Int32.Parse(temp1);

j = Int32.Parse(temp2);

k =i / j;

}

catch (Exception e)

{

Console.WriteLine("Error general, introduzca mejor sus datos");

}

Console.WriteLine("El resultado de dividir {0} por {1} es {2}", i, j, k);

}

}

}

0 Comments:

Post a Comment

<< Home