Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. private void button4_Click(object sender, EventArgs e)
  2.         {
  3.             int[] notas = new int[12];
  4.             for (int i = 0; i < 12; i++)
  5.             {
  6.                 notas[i] = Convert.ToInt32(formandos[i, 1]);
  7.             }
  8.             label3.Text=  label3.Text + Convert.ToString(GetMax(notas));
  9.             label4.Text = label4.Text + Convert.ToString(GetMin(notas));
  10.             label5.Text = label5.Text + Convert.ToString(GetAvg(notas));
  11.            
  12.         }
  13.         public static int GetMax(int[] intCollection)
  14.         {
  15.             int max = int.MinValue;
  16.             foreach (int i in intCollection)
  17.             {
  18.                 if (i > max)
  19.                 {
  20.                     max = i;
  21.                 }
  22.             }
  23.            
  24.             return max;
  25.         }
  26.  
  27.         public static int GetMin(int[] intCollection)
  28.         {
  29.             int min = intCollection[0];
  30.             foreach (int i in intCollection)
  31.             {
  32.                 if (i < min)
  33.                 {
  34.                     min = i;
  35.                 }
  36.             }
  37.  
  38.             return min;
  39.         }
  40.  
  41.         public static int GetAvg(int[] intCollection)
  42.         {
  43.             int avg = 0;
  44.             foreach (int i in intCollection)
  45.             {                
  46.                     avg += i;                
  47.             }
  48.  
  49.             return avg/intCollection.Length;
  50.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement