-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercicio C# Função.cs
56 lines (44 loc) · 1.35 KB
/
Exercicio C# Função.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
namespace prog_estruturad
{
class Exercicio19Revisao
{
static void Main(string[] args){
// Exercicio 19 Revisao
float n1, n2;
string op;
Console.WriteLine("Digite um numero: ");
n1 = float.Parse(Console.ReadLine());
Console.WriteLine("Digite outro numero: ");
n2 = float.Parse(Console.ReadLine());
Console.WriteLine("Escolha (+, -, *, /): ");
op = Console.ReadLine();
Console.WriteLine(calc(n1,n2,op));
//fim
}
static float calc(float a, float b, string operador){
switch (operador)
{
case "+":
return a + b;
//break;
case "-":
return a - b;
//break;
case "*":
return a * b;
//break;
case "/":
if (a == 0){
return 0;
} else {
return a / b;
}
//break;
default:
return 0;
//break;
}
}
}
}