void Update() { if (Specimen != null) { float Min = int.MaxValue; float Max = int.MinValue; float Med; float Sum = 0; List <float> results = new List <float>(); foreach (SpecimenScript speciman in Specimen) { float score = speciman.FinalScore(); Sum += score; results.Add(score); } results.Sort(); Min = results[0]; Max = results[results.Count - 1]; Med = (results.Count % 2 == 0 && results.Count > 1) ? (results[results.Count / 2] + results[results.Count / 2 - 1]) / 2 : results[results.Count / 2]; WorstScoreText.text = Min.ToString("n0"); BestScoreText.text = Max.ToString("n0"); AverageScoreText.text = (Sum / Specimen.Length).ToString("n1"); MedianScoreText.text = Med.ToString("n1"); } }
private void CMDMED_Click(object sender, EventArgs e) { //Programa que ingresa 20 numeros y obtiene la mediana //Silva Reyes Luis Adrian 19210549 //Tarea#40 //Declaracion de variables int C = 0, Med; int A, B; int Temp; int[] Num; Num = new int[20]; //Generador de aleatorio enteros Random aleatorio = new Random(); //Despliegue de resultado for (C = 1; C < 20; C = C + 1) { //Asignacion de variables Num[C] = aleatorio.Next(100); TXTN.Text = TXTN.Text + Num[C] + "\t"; } for (A = 1; A < 20; A = A + 1) { for (B = 1; B < 20; B = B + 1) { if (Num[B - 1] > Num[B]) { Temp = Num[B - 1]; Num[B - 1] = Num[B]; Num[B] = Temp; } } } //Mediana Med = ((Num[10]) + (Num[11])) / 2; //Salida TXTMED.Text = "La mediana es:" + Med.ToString(); }
private void CMDPAR_Click(object sender, EventArgs e) { //Programa que captura 10 numeros y menciona los pares,su suma y media //Silva Reyes Luis Adrian 19210549 //Tarea#37 //Declaracion de variables int C, Med, Par, Par1 = 0; int Num; int Suma = 0; //Generador de numeros aleatorios Random aleatorio = new Random(); //Despliegue de resultados for (C = 1; C <= 10; C++) { Num = aleatorio.Next(100); //Par Par = Num % 2; if (Par == 0) { TXTPAR.Text = TXTPAR.Text + "Numero es par:" + Num + "\r\n"; Par1 = Par1 + 1; Suma = Suma + Num; } else { TXTPAR.Text = TXTPAR.Text + "Numero es impar:" + Num + "\r\n"; } } //Media Med = Suma / 10; //Salida de datos TXTSUMA.Text = "La suma es:" + Suma.ToString(); TXTPAR1.Text = "Los numeros pares son:" + Par1.ToString(); TXTMED.Text = "La media es:" + Med.ToString(); }
/// <summary> /// Converts the Five-Number Summary to a string /// </summary> /// <returns> /// A string in the form of "[Min Q1 Med Q3 Max]", using values from /// the summary. /// </returns> public override string ToString() { return("[" + Min.ToString() + " " + Q1.ToString() + " " + Med.ToString() + " " + Q3.ToString() + " " + Max.ToString() + "]"); }