Vous êtes sur la page 1sur 3

Funções e Procedimentos

void calcular1() // Procedimento - não devolve nada


{
int num = Convert.ToInt16(txNum.Text);

if (num % 2 == 0)
{
txRes.Text = "S";
txRes.BackColor = Color.Green;
}
else
{
txRes.Text = "N";
txRes.BackColor = Color.Red;
}
}

string calcular2() // Funçáo - devolve algo


{
int num = Convert.ToInt16(txNum.Text);
string inf;

if (num % 2 == 0)
{
inf = "S";
}
else
{
inf = "N";
}
return inf;
}

1
private void button1_Click(object sender, EventArgs e)
{
int num = Convert.ToInt16(txNum.Text);

if (num % 2 == 0)
{
txRes.Text = "S";
txRes.BackColor = Color.Green;
}
else
{
txRes.Text = "N";
txRes.BackColor = Color.Red;
}
}

private void button2_Click(object sender, EventArgs e)


{
int num = Convert.ToInt16(txNum.Text);

if (num % 2 == 0)
{
txRes.Text = "S";
txRes.BackColor = Color.Green;
}
else
{
txRes.Text = "N";
txRes.BackColor = Color.Red;
}
}

string calcular3(int num) // Funçáo - devolve algo


{
string inf;

if (num % 2 == 0)
{
inf = "S";
}
else
{
inf = "N";
}
return inf;
}
private void button3_Click(object sender, EventArgs e)
{
calcular1();
}

private void button4_Click(object sender, EventArgs e)


{
calcular1();
}

private void button5_Click(object sender, EventArgs e)


{
txRes.Text = calcular2();
}

2
private void button6_Click(object sender, EventArgs e)
{

private void button7_Click(object sender, EventArgs e)


{
int num = Convert.ToInt16(txNum.Text);
txRes.Text = calcular3(num);
}

int soma(int v1, int v2)


{
int calc = v1 + v2;
return calc;
}

private void button8_Click(object sender, EventArgs e)


{
int v1 = Convert.ToInt16(txN1.Text);
int v2 = Convert.ToInt16(txN2.Text);

txFinal.Text = soma(v1, v2).ToString();


}

int subtracao(int v1, int v2)


{
int calc = v1 - v2;
return calc;
}

private void button9_Click(object sender, EventArgs e)


{
int v1 = Convert.ToInt16(txN1.Text);
int v2 = Convert.ToInt16(txN2.Text);

txFinal.Text = subtracao(v1, v2).ToString();


}

double media(double v1, double v2)


{
double calc = (v1 + v2) / 2;
return calc;
}

private void button10_Click(object sender, EventArgs e)


{
double v1 = Convert.ToDouble(txN1.Text);
double v2 = Convert.ToDouble(txN2.Text);

txFinal.Text = media(v1, v2).ToString();


}
}

Vous aimerez peut-être aussi