double n, x = 0, valor = 0, suma = 0, prom = 0;
PRINT("Cuantos numeros quiere sumar");
READ n
for (x = 1; x <= n; x = x + 1)
{
PRINT("Introduce numero ", x);
READ valor
suma = suma + valor;
prom = suma / n;
}
PRINT("La suma es = " + suma + "El promedio es = " + prom);
FINAL
CODIGO EN CONSOLA:
double n, x = 0, valor = 0, suma = 0, prom = 0;
Console.WriteLine("Cuantos numeros quiere sumar");
n = double.Parse(Console.ReadLine());
for (x = 1; x <= n; x = x + 1)
{
Console.WriteLine("Introduce numero ", x);
valor = double.Parse(Console.ReadLine());
suma = suma + valor;
prom = suma / n;
}
Console.WriteLine("\nLa suma es = " + suma + "\n\nEl promedio es = " + prom);
Console.ReadKey();
CODIGO EN WINDOWS
public partial class Form1 : Form
{
int[] temp;
int I=0, suma, P,n;
public Form1()
{
InitializeComponent();
temp = new int[8];
I = suma = P = 0; listBox1.Items.Add("Lista de numeros enteros");
}
private void button3_Click(object sender, EventArgs e)
{
I = 0;
textBox1.Text = "";
textBox2.Text = "";
listBox1.Items.Clear();
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
n = int.Parse(textBox1.Text);
if(I
temp[I]=int.Parse(textBox2.Text);
suma=suma+temp[I];
listBox1.Items.Add(temp[I]);
textBox2.Clear();
textBox2.Focus();
I++;
}
else
{
textBox2.Clear();
textBox2.Enabled=false;
button1.Enabled=false;
}
}
private void button2_Click(object sender, EventArgs e)
{
suma=suma+temp[I];
P= suma/n;
listBox1.Items.Add("\n\nSuma = " +suma.ToString());
listBox1.Items.Add("\n\nPromedio = "+ P.ToString() );
}

No hay comentarios:
Publicar un comentario