lunes, 7 de diciembre de 2009

PRACTICA # 10.2 (ARREGLO DE POTENCIA )

pseudocodigo.
Real[] resistencia ={16,27,39,56,81};
Real[] corriente = new int [5];

Real[] potencia = new int[5];
Real total = 0, I = 0;

for (I = 0 TO 4 STEP I=I+1)
{ print("Introduce corriente",I);
Read corriente[I] potencia[I] = resistencia[I] * (corriente[I] * corriente[I]);
total = total + potencia[I];

} print( Resistencia Corriente Potencia );
for (I = 0 TO 4 STEP I=I+1)
{
print( resistencia[I], corriente[I], potencia[I]);
}
print("Total + total);

FINAL

CONSOLA




int[] resistencia = { 16, 27, 39, 56, 81 };

int[] corriente = new int[5];
int[] potencia = new int[5];
int total = 0, I = 0;
for (I = 0; I <= 4; I++)
{ Console.WriteLine("Introduce corriente", I);
corriente[I] = int.Parse(Console.ReadLine());

potencia[I] = resistencia[I] * (corriente[I] * corriente[I]);
total = total + potencia[I];

}

Console.WriteLine(" Resistencia\tCorriente\tPotencia");
for (I = 0; I <= 4; I++)
{
Console.WriteLine(" {0}\t\t{1}\t\t{2}", resistencia[I], corriente[I], potencia[I]);

}
Console.WriteLine("en total= " + total);
Console.ReadKey();

VISUAL

public partial class Form1 : Form
{
int[] resistencia = { 16, 27, 39, 56, 81 };
int[] corriente = new int[5];
int[] potencia = new int[5];
int total = 0, I = 0;
public Form1()
{
InitializeComponent();
total = 0;

listBox1.Items.Add("RESISTENCIA CORRIENTE POTENCIA");
}
private void button1_Click(object sender, EventArgs e)
{
if (I <>
{
textBox1.Focus();
corriente[I] = int.Parse(textB
ox1.Text);
potencia[I] = resistencia[I] * (corriente[I] * corriente[I]);
textBox1.Clear();
total = total + potencia[I];
listBox1.Items.Add(resistencia[I].ToString() + "\t\t" + corriente[I].ToString() + "\t\t" + potencia[I].ToString());
I++;
}

else
{
button1.Enabled = false;
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = ("EL resultado es=" + total.ToString());

}
private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
textBox1.Clear();
textBox2.Clear();
textBox1.Enabled = true;
button1.Enabled = true;

}
private void button4_Click(object sender, EventArgs e)
{
Close();
}
}
}


No hay comentarios:

Publicar un comentario