EJERCICIO 01
CÓDIGO:
namespace EJERCICIO1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
{
try
{
int num1 = int.Parse(txtNum1.Text);
int num2 = int.Parse(txtNum2.Text);
int suma = num1 + num2;
label3.Text = "Resultado: " + suma.ToString();
}
catch (FormatException)
{
MessageBox.Show("Por favor, ingrese números válidos.");
}
}
}
}
}
EJERCICIO 02
CÓDIGO:
namespace EJERCICIO2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
{
try
{
double celsius = double.Parse(txtDigita.Text);
double fahrenheit = (celsius * 9 / 5) + 32;
label2.Text = "°Fahrenheit: " + fahrenheit.ToString("F2");
}
catch (FormatException)
{
MessageBox.Show("Por favor, ingrese un número válido.");
}
}
}
private void label1_Click(object sender, EventArgs e)
{}
}
}
EJERCICIO 03
CÓDIGO:
namespace EJERCICIO3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
int numero = int.Parse(txtNum.Text);
if (numero % 2 == 0)
{
label2.Text = "El número es par.";
}
else
{
label2.Text = "El número es impar.";
}
}
catch (FormatException)
{
MessageBox.Show("Por favor, ingrese un número válido.");
}
}
}
}
EJERCICIO 04
CÓDIGO:
namespace EJERCICIO4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
double peso = double.Parse(txtPeso.Text);
double altura = double.Parse(txtTalla.Text);
double imc = peso / (altura * altura);
string diagnostico;
if (imc < 18.5)
{
diagnostico = "Bajo peso.";
}
else if (imc >= 18.6 && imc <= 24.9)
{
diagnostico = "Peso saludable.";
}
else if (imc >= 25.0 && imc <= 29.9)
{
diagnostico = "Sobrepeso.";
}
else
{
diagnostico = "Obesidad.";
}
label3.Text = $"IMC: {imc:F2} - Diagnóstico: {diagnostico}";
}
catch (FormatException)
{
MessageBox.Show("Por favor, ingrese valores válidos.");
}
}
}
}
EJERCICIO 05
CÓDIGO:
using System;
namespace EJERCICIO5
{
public partial class Form1 : Form
{
Random random = new Random();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
{
try
{
int limiteInferior = int.Parse(txtLimInf.Text);
int limiteSuperior = int.Parse(txtLimSup.Text);
if (limiteInferior < limiteSuperior)
{
int numeroAleatorio = random.Next(limiteInferior, limiteSuperior + 1);
label3.Text = "Número aleatorio: " + numeroAleatorio.ToString();
}
else
{
MessageBox.Show("El límite inferior debe ser menor que el límite superior.");
}
}
catch (FormatException)
{
MessageBox.Show("Por favor, ingrese números válidos.");
}
}
}
}
}