Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save pbalduino/74c319cd5e502d3f0dbb to your computer and use it in GitHub Desktop.
Cálculo de média sem array
private void btnCalcular_Click(object sender, EventArgs e)
{
decimal maior = 0;
decimal menor = 99;
if (txtNota0.Value < menor) menor = txtNota0.Value;
if (txtNota1.Value < menor) menor = txtNota1.Value;
if (txtNota2.Value < menor) menor = txtNota2.Value;
if (txtNota3.Value < menor) menor = txtNota3.Value;
lblMenor.Text = menor.ToString();
if (txtNota0.Value > maior) maior = txtNota0.Value;
if (txtNota1.Value > maior) maior = txtNota1.Value;
if (txtNota2.Value > maior) maior = txtNota2.Value;
if (txtNota3.Value > maior) maior = txtNota3.Value;
lblMaior.Text = maior.ToString();
decimal media = (txtNota0.Value + txtNota1.Value + txtNota2.Value + txtNota3.Value) / 4;
lblMedia.Text = media.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment