/
Calculator.cs
73 lines (62 loc) · 1.51 KB
/
Calculator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Linq;
namespace Api.Model
{
public class Calculator:IDisposable
{
public int Sum(int n1, int n2)
{
//return n1/n2;
return n1 + n2;
}
public int Sub(int n1, int n2)
{
return n1 - n2;
}
public int Division(int n1, int n2)
{
return n1 / n2;
}
public int Multiplication(int n1, int n2)
{
return n1 * n2;
}
public bool IsPrime(int n)
{
if (n > 1)
{
return Enumerable.Range(1, n).Where(x => n % x == 0)
.SequenceEqual(new[] { 1, n });
}
return false;
}
public bool isOdd(int number)
{
return (number % 2 != 0);
}
public int Calculate(int n1, int n2, Action action)
{
int result = 0;
if (action == Action.Division)
result = n1 / n2;
else if (action == Action.Multiplication)
result = n1 * n2;
else if (action == Action.Sub)
result = n1 - n2;
else if (action == Action.Sum)
result = n1 + n2;
return result;
}
public void Dispose()
{
throw new NotImplementedException();
}
}
public enum Action
{
Sum = 0,
Sub = 1,
Division = 2,
Multiplication = 3
}
}