Skip to content

Instantly share code, notes, and snippets.

@pbalduino
Created November 12, 2014 11:22
Show Gist options
  • Select an option

  • Save pbalduino/f2d52c836f4cbdca0c7e to your computer and use it in GitHub Desktop.

Select an option

Save pbalduino/f2d52c836f4cbdca0c7e to your computer and use it in GitHub Desktop.
Cálculo de média usando for
private void btnCalcular_Click(object sender, EventArgs e)
{
decimal[] notas = new decimal[4];
notas[0] = txtNota0.Value;
notas[1] = txtNota1.Value;
notas[2] = txtNota2.Value;
notas[3] = txtNota3.Value;
Array.Sort(notas);
lblMenor.Text = notas[0].ToString();
lblMaior.Text = notas[3].ToString();
int p = 0;
decimal total = 0;
for (p = 0; p < 4; p = p + 1)
{
total = total + notas[p];
}
decimal media = total / 4;
lblMedia.Text = media.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment