0% found this document useful (0 votes)
23 views3 pages

Public Int New Int Int: //media

This document contains code for calculating statistics like mean, median, mode, variance, and standard deviation of a data set. It defines arrays to store input values and calculated statistics. Methods are included to calculate each statistic as well as clear inputs, add new values, and exit. The statistics are displayed in text boxes when the calculate button is clicked.

Uploaded by

Fernando Ortiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Public Int New Int Int: //media

This document contains code for calculating statistics like mean, median, mode, variance, and standard deviation of a data set. It defines arrays to store input values and calculated statistics. Methods are included to calculate each statistic as well as clear inputs, add new values, and exit. The statistics are displayed in text boxes when the calculate button is clicked.

Uploaded by

Fernando Ortiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

public int[] valor = new int[10000];

int i = -1 ;
Double media = 0.0, m = 0, total = 0;
Double mediana=0.0, Vvarianza=0.0,Varianza=0.0, Destandar=0.0;
Double Mmediana = 0.0;

private void btnsalir_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void btnlimpiar_Click(object sender, EventArgs e)


{
Application.Restart();
}

private void btncalcular_Click(object sender, EventArgs e)


{
//media
for (i = 0; i <= total ; i++)
{
m = m + valor[i];

media = m / total;

txtmedia.Text = Convert.ToString(media);

//mediana

for (i = 0; i < total - 1; i++)


{
for (int j = i + 1; j < total; j++)
{
if (valor[i] < valor[j])
{
int aux = valor[i];
valor[i] = valor[j];
valor[j] = aux;
}
}
}

Mmediana = total / 2;
Mmediana = Mmediana / 2;
if (Mmediana % 1 == 0)
{
Double valor1 = valor[Convert.ToInt16(Mmediana)];
Double valor2 = valor[Convert.ToInt16(Mmediana) + 1];
mediana = (valor1 + valor2) / 2;

Reyes Alvarado Carlos Alberto – Tópicos avanzados de programación


else
{
Mmediana = Mmediana + 1;
mediana = valor[Convert.ToInt16(Mmediana)];
}

txtmediana.Text = ("" + mediana);

//moda

int Maximo = 0;
int moda = 0;
int repe = 0;
for (i = 0; i < total; i++)
{

for (int j = 0; j < total; j++)


{
if (valor[i] == valor[j])
{
repe++;
}

}
if (repe > Maximo)
{
moda = valor[i];
Maximo = repe;
}

txtmoda.Text = Convert.ToString(moda);

//varianza

if (total - 1 == 0)
{
MessageBox.Show("Error, no se puede dividir entre cero");
}
else
{
for (i = 0; i <= total; i++)
{
Vvarianza = Vvarianza + ((valor[i] - media) * (valor[i] -
media));
}
Varianza = Vvarianza / (total - 1);
Varianza = Varianza / 2;
txtvarianza.Text = Convert.ToString(Varianza);
}

//desviación estandar

Reyes Alvarado Carlos Alberto – Tópicos avanzados de programación


Destandar = Math.Sqrt(Varianza);
txtdesestandar.Text = Convert.ToString(Destandar);

private void btnañadir_Click(object sender, EventArgs e)


{
if (txtvalor.Text == "")
{
MessageBox.Show("Ingrese un valor en el campo");
}
else
{
i = i + 1;
valor[i] = Convert.ToInt16(txtvalor.Text);
total = total + 1;
txtvalor.Clear();
txtvalor.Focus();

Reyes Alvarado Carlos Alberto – Tópicos avanzados de programación

You might also like