Escolar Documentos
Profissional Documentos
Cultura Documentos
Ejercicios prcticos
1. Crear un formulario que permita hallar la solucin de una ecuacin de
primer grado de la forma ax + b = 0, la solucin de este tipo de
ecuaciones est dado por x = -b/a con a diferente de cero.
private void button1_Click(object sender, EventArgs e)
{
double a, b, x;
a = Double.Parse(txta.Text);
b = Double.Parse(txtb.Text);
if (a != 0)
{
x = -b / a;
MessageBox.Show("La solucion es x =" +x);
}
else
MessageBox.Show("Error a debe ser diferente de cero");
}
private void btnlimpiar_Click(object sender, EventArgs e)
{
txta.Clear();
txtb.Clear();
}
private void btnsalir_Click(object sender, EventArgs e)
{
Close();
}
}
{ m = b; }
if (c > m)
{
m = c;
}
if (d > m)
{
m = d;
}
if (n > m)
{
m = n;
}
MessageBox.Show("El mayor es:" + m);
}
private void btnlimpiar_Click(object sender, EventArgs e)
{
txtnum1.Clear();
txtnum2.Clear();
txtnum3.Clear();
txtnum4.Clear();
txtnum5.Clear();
}
}
else { MessageBox.Show("La ecuacin no tiene solucin en los reales"); }
}
}
else { MessageBox.Show("Error a debe ser diferente de cero"); }
}
private void btnlimpiar_Click(object sender, EventArgs e)
{
txta.Clear();
txtb.Clear();
txtc.Clear();
}
Etsunp.edu.pe/campus
Usuario:jmedinac9
Clave: $$%%&&mate
4. Crear un formulario que permita leer un nmero entero, luego
determinar la cantidad de divisores que tiene el nmero.
private void btncalcular_Click(object sender, EventArgs e)
{
int N, I, cantdiv;
N = Int32.Parse(txta.Text);
cantdiv = 1;
I = 2;
while (I <= N)
{
if (N % I == 0)
cantdiv = cantdiv + 1;
I = I + 1;
}
MessageBox.Show("La cantidad de divisores es:" + cantdiv);
}
}
}
String mensaje;
public String Ecuacion1(double CoefA, double CoefB)
{
double x;
if (CoefA != 0)
{
x = -CoefB / CoefA;
mensaje = "La solucion es x =" +x;
}
else
mensaje = "Error a debe ser diferente de cero";
return mensaje;
}
public String Ecuacion2(double CoefA, double CoefB, double CoefC)
{
double x1, x2, x3, D;
if (CoefA != 0)
{
D = CoefB * CoefB - 4 * CoefA * CoefC;
if (D > 0)
{
x1 = (-CoefB + Math.Sqrt(D)) / (2 * CoefA);
x2 = (-CoefB - Math.Sqrt(D)) / (2 * CoefA);
mensaje = "Las soluciones son: x1 = " + x1 + " y " + "x2 = " + x2;
}
else
{
if (D == 0)
{
x3 = -CoefB / (2 * CoefA);
mensaje = "La solucion es: x=" + x3;
}
else { mensaje = "La ecuacin no tiene solucin en los reales"; }
}
}
else { mensaje = "Error a debe ser diferente de cero"; }
return mensaje;
}
Primo
int N, I, cantdiv;
N = Int32.Parse(txta.Text);
cantdiv = 1;
I = 2;
while (I <= N)
{
if (N % I == 0)
cantdiv = cantdiv + 1;
I = I + 1;
}
if (cantdiv == 2)
MessageBox.Show("El numero es primo");
else
{
if (cantdiv == 1)
MessageBox.Show("El numero es simple");
else
MessageBox.Show("El numero no es primo");
}
int N, I, J = 0;
bool esprimo;
double[] Numero = new Double[100];
N = 2;
while(N<=100)
{ I=2;
esprimo = true;
while (I <= N/2)
{
if (N % I == 0)
{
esprimo = false;
break;
}
I = I + 1;
}
if(esprimo==true)
{
Numero[J] = N;
J = J + 1;
}
//listBox1.Items.Add(N.ToString());
N = N + 1;
}
Formulario
Matematica oMatematica = new Matematica();
MessageBox.Show(oMatematica.Ecuacion2(Double.Parse(txta.Text),
Double.Parse(txtb.Text), Double.Parse(txtc.Text)));