lunes, 2 de noviembre de 2009

8.2_(a), (b) y (c) consola y windows

PSEUDOCODIGO
int[] emax = new int[10];
int I, mayor;
PRINT("Introduce un munero entero");
READ emax[0]
mayor = emax[0];
for (I = 1; I < 10; I++)
{PRINT("Introduce dato{0}", I);
READ emax[I]
if (emax[I] > mayor)
{
mayor = emax[I];
}
}

PRINT("Lista de 10 numeros enteros");
for (I = 0; I < 10; I++)
{
PRINT(emax[I]);
}

PRINT("el valor maximo es {0}: ", mayor);
Console.ReadLine();


CODIGOS EN CONSOLA A , B , C

A)
int[] emax = new int[10];
int I, mayor;
Console.WriteLine("Introduce un munero entero");
emax[0] = int.Parse(Console.ReadLine());
mayor = emax[0];
for (I = 1; I < 10; I++)
{
Console.WriteLine("Introduce dato{0}", I);
emax[I] = int.Parse(Console.ReadLine());
if (emax[I] > mayor)
{
mayor = emax[I];
}
}

Console.WriteLine("Lista de 10 numeros enteros");
for (I = 0; I < 10; I++)
{
Console.WriteLine(emax[I]);
}

Console.WriteLine("el valor maximo es {0}: ", mayor);
Console.ReadLine();



B)

int[] emax = new int[10];
int I, mayor,pos=0;

Console.WriteLine("Introduce un munero entero");
emax[0] = int.Parse(Console.ReadLine());
mayor = emax[0];
for (I = 1; I < 10; I++)
{
Console.WriteLine("Introduce dato{0}",I);
emax[I] = int.Parse(Console.ReadLine());
if (emax[I] > mayor)
{
mayor = emax[I];
pos=I;

}
}

Console.WriteLine("Lista de 10 numeros enteros");
for (I = 0; I < 10; I++)
{
Console.WriteLine(emax[I]);
}

Console.WriteLine("el valor maximo es {0}: ", mayor);
Console.WriteLine("Este es el elemento numero {0} de la lista de numero", pos);
Console.ReadLine();


C)

int[] emax = new int[10];
int I, menor, pos = 0;

Console.WriteLine("Introduce un munero entero");
emax[0] = int.Parse(Console.ReadLine());
menor = emax[0];
for (I = 1; I < 10; I++)
{
Console.WriteLine("Introduce dato{0}", I);
emax[I] = int.Parse(Console.ReadLine());
if (emax[I] {menor = emax[I];
pos = I;

}
}

Console.WriteLine("Lista de 10 numeros enteros");
for (I = 0; I < 10; I++)
{
Console.WriteLine(emax[I]);
}

Console.WriteLine("el valor menor es {0}: ", menor);
Console.WriteLine("Este es el elemento numero {0} de la lista de numero", pos);
Console.ReadLine();








CODIGOS EN WINDOWS


A Y B
public partial class Form1 : Form
{
int[] Emax = new int[10];
int I, mayor, pos = 0;
public Form1()
{

InitializeComponent();
I = 0;
listBox1.Items.Add("Valores enteros:");
}

private void button1_Click(object sender, EventArgs e)
{
if (I < 10)
{


Emax[I] = int.Parse(textBox1.Text);
if (I == 0)
{


mayor = Emax[0];
}
textBox1.Focus();
textBox1.Clear();

listBox1.Items.Add(I.ToString() + ":\t" + Emax[I].ToString());

if (Emax[I] > mayor)
{
mayor = Emax[I];
pos = I;
}

I++;
}

else
{
button1.Enabled = false;
}

}

private void button2_Click(object sender, EventArgs e)
{
label2.Text=("El valor maximo es: " + mayor.ToString() );
label3.Text=("Posicion numero: " + pos.ToString());
}




C)
public partial class Form1 : Form
{
int[] corriente;
int[] resistencia;
int[] voltios;
int I;
public Form1()
{
InitializeComponent();
corriente = new int[10];
resistencia = new int[10];
voltios = new int[10];
I = 0;
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
if (I <= 10)
{

textBox1.Focus();
corriente[I] = int.Parse(textBox1.Text);


resistencia[I] = int.Parse(textBox2.Text);

voltios[I] = corriente[I] * resistencia[I];
I++;
textBox2.Clear();
textBox1.Clear();
}

else
{

button1.Enabled=false;
}



}

private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add("Corriente Resistencia Voltios");
for (I = 0; I < 10; I++)
{
listBox1.Items.Add(corriente[I].ToString() + "\t\t" + resistencia[I].ToString() + "\t\t" + voltios[I].ToString());
}

}

No hay comentarios:

Publicar un comentario