martes, 27 de abril de 2010

Practica 10 Problema 2

Practica 10 problema 2 "En consola"

Codigo:
namespace practica_10__problema_2
{
class Program
{
static void Main(string[] args)
{
double[] pendiente = { 17.24, 25.63, 5.94, 33.92, 3.71, 31.84, 45.90, 35.99, 18.44, 6.92, 12.2, 29.45, 13.89, 5.21, 2.56, 8.77, 23.99, 7.23, 31.96 };
double max = pendiente[0];
int pmax = 0;
double min = pendiente [0];
int pmin = 0;
int i = 0;
for (i = 0; i < 19; i = i + 1)
{
if (pendiente[i] > max)
{
max = pendiente[i];
pmax = i;
}
if (pendiente[i] < min)
{
min = pendiente[i];
pmin = i;
}
}
Console.WriteLine("Pendiente");
for (i = 0; i < 19; i = i + 1)
{
Console.WriteLine(" "+ pendiente[i]);
}
Console.WriteLine("Pendiente mayor= " + max);
Console.WriteLine("Esta en la posicion= " + pmax);
Console.WriteLine("Pendinte menor= "+min);
Console.WriteLine("Esta en la posicion= "+pmin);
Console.ReadKey();
}
}
}

Practica 10 problema 2 "En visual"

Codigo:
namespace practica_10_problema_2_visual
{
public partial class Form1 : Form
{
double[] pendiente;
int i, pmax, pmin;
double max, min;
public Form1()
{
InitializeComponent();
pendiente = new double[19] { 17.24, 25.63, 5.94, 33.92, 3.71, 31.84, 45.90, 35.99, 18.44, 6.92, 12.2, 29.45, 13.89, 5.21, 2.56, 8.77, 23.99, 7.23, 31.56 };
i = pmax = pmin = 0;
double max = min = pendiente[0];
listBox1.Items.Add("\tPendiente");
}


private void button1_Click(object sender, EventArgs e)
{


for (i = 0; i < 19; i = i + 1)
{
if (pendiente[i] > max)
{
max = pendiente[i];
pmax = i;

}
}
for(i=0;i<19;i=i+1)
{
if (pendiente[i] < min)
{
min = pendiente[i];
pmin = i;
}
}

for (i=0; i<19; i=i+1)
{
listBox1.Items.Add("\t"+pendiente[i]);
button1.Enabled = false;

}
listBox1.Items.Add("Pendiente mayor= " + max);
listBox1.Items.Add("Esta en la posicion= " + pmax);
listBox1.Items.Add("Pendiente menor= " + min);
listBox1.Items.Add("Esta en la posicion= " + pmin);

}

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

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


Pseudocodigo:
pendiente [19] = { 17.24, 25.63, 5.94, 33.92, 3.71, 31.84, 45.90, 35.99, 18.44, 6.92, 12.2, 29.45, 13.89, 5.21, 2.56, 8.77, 23.99, 7.23, 31.96 } double
max = pendiente[0] double
pmax = 0 int
min = pendiente [0] double
pmin = 0 int
i = 0 int
for (i=0 to 19 step i = i + 1)
{
if (pendiente[i] > max)
{
max = pendiente[i];
pmax = i;
}
if (pendiente[i] < min)
{
min = pendiente[i];
pmin = i;
}
}
print"Pendiente"
for (i=0 to 19 step i = i + 1)
{
print pendiente[i]
}
print "Pendiente mayor= ", max
print "Esta en la posicion= ", pmax
print "Pendinte menor= ", min
print "Esta en la posicion= ", pmin
fin

No hay comentarios:

Publicar un comentario