miércoles, 21 de abril de 2010

Practica 9

Practica 9_1 consola
static void Main(string[] args)
{
int[] temp = new int[10];

int total;
int i;
int prom;
total=0;
i = 0;
prom = 0;
Console.WriteLine("Introducelos siguientes elementos");
for(i=0;i<10;i=i+1) total="total+temp[i];" prom="total/10;" i =" 0;" i =" i" style="color: rgb(255, 153, 0);">practica 9_1visual
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int[] temp;
int i, total, prom;
public Form1()
{

InitializeComponent();
temp = new int[10];
total = prom = i=0;

}

private void button1_Click(object sender, EventArgs e)
{
if(i<10) { temp[i]=int.Parse(textBox1.Text); total=total+temp[i]; listBox1.Items.Add("valor"+i+" "+ temp[i]); i=i+1; textBox1.Clear(); textBox1.Focus(); } if(i==10) { textBox1.Enabled=false; button1.Enabled=false; } } private void button2_Click(object sender, EventArgs e) { prom=total/10; listBox1.Items.Add("Promedio= "+prom); } private void button3_Click(object sender, EventArgs e) { textBox1.Enabled = true; button1.Enabled = true; listBox1.Items.Clear(); } } }
Practica 9_2 consola

static void Main(string[] args)
{
int[] corriente = new int[10];
int[] resistencia = new int[10];
int[] voltios = new int[10];
int i;


Console.Write("Introduce los valores de la corriente");
for (i = 0; i < i =" i" i =" 0;" i =" i" i =" 0;" i =" i" style="color: rgb(255, 153, 0);">Practica 9_2visual
namespace WindowsFormsApplication1
{
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];
listBox1.Items.Add("corriente resistencia voltaje");
i = 0;

}

private void button1_Click(object sender, EventArgs e)
{

if (i <= 10) { corriente[i] = int.Parse(textBox1.Text); resistencia[i] = int.Parse(textBox2.Text); voltios[i] = resistencia[i] * corriente[i]; listBox1.Items.Add( " "+resistencia[i]+" "+corriente[i]+" "+voltios[i]); i = i + 1; textBox1.Clear(); textBox1.Focus(); textBox2.Clear(); textBox2.Focus(); } if (i == 10) { textBox1.Enabled = false; textBox2.Enabled = false; button1.Enabled = false; } } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { textBox1.Enabled = true; textBox2.Enabled = true; button1.Enabled = true; listBox1.Items.Clear(); } } } practica 9_2 consola using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] corriente = new int[10]; int[] resistencia = new int[10]; int[] voltios = new int[10]; int i; Console.Write("Introduce los valores de la corriente"); for (i = 0; i < 10; i = i + 1) { Console.WriteLine("corriente[{0}]" , i); corriente[i] = int.Parse(Console.ReadLine()); } Console.WriteLine("Introduce los valores de resistencia"); for (i = 0; i < 10; i = i + 1) { Console.WriteLine("resistencia[{0}]", i); resistencia[i] = int.Parse(Console.ReadLine()); } Console.WriteLine("corriente resistencia voltios"); for (i = 0; i < 10; i = i + 1) { voltios[i] = resistencia[i] * corriente[i]; Console.WriteLine(+corriente[i] + " " + resistencia[i] + " " + voltios[i]); } Console.ReadKey(); } } }
Practica 9_2 visual

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
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];
listBox1.Items.Add("corriente resistencia voltaje");
i = 0;

}

private void button1_Click(object sender, EventArgs e)
{

if (i <= 10)
{
corriente[i] = int.Parse(textBox1.Text);
resistencia[i] = int.Parse(textBox2.Text);
voltios[i] = resistencia[i] * corriente[i];
listBox1.Items.Add( " "+resistencia[i]+" "+corriente[i]+" "+voltios[i]);
i = i + 1;
textBox1.Clear();
textBox1.Focus();
textBox2.Clear();
textBox2.Focus();


}
if (i == 10)
{
textBox1.Enabled = false;
textBox2.Enabled = false;
button1.Enabled = false;
}


}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Enabled = true;
textBox2.Enabled = true;
button1.Enabled = true;

listBox1.Items.Clear();


}
}
}

No hay comentarios:

Publicar un comentario