-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharithmetic.php
75 lines (59 loc) · 975 Bytes
/
arithmetic.php
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
74
75
<?php
$number='cat';
function throwErrorMessage($value){
echo $value . " Is Invalid Input!" . PHP_EOL;
}
function checkNumber($number){
if (is_numeric($number)){
return $number;
}else{
throwErrorMessage($number);
};
}
function add($a, $b=null)
{
checkNumber($a);
checkNumber($b);
return $a + $b;
}
function subtract($a, $b=1)
{
checkNumber($a);
checkNumber($b);
return $a-$b;
}
function multiply($a, $b)
{
checkNumber($a);
checkNumber($b);
return $a*$b;
}
function divide($a, $b)
{
checkNumber($a);
checkNumber($b);
if ($b!=0) {
return $a/$b;
}else{
throwErrorMessage($b);
}
}
function modulus($a, $b)
{
checkNumber($a);
checkNumber($b);
return $a%$b;
}
function squareRoot($a){
checkNumber($a);
return sqrt($a);
}
function squared($a){
checkNumber($a);
return $a * $a;
}
echo add(6,6) . PHP_EOL;
echo subtract(7,6) . PHP_EOL;
echo multiply(7,6) . PHP_EOL;
echo divide(7,0) . PHP_EOL;
echo modulus(6,4) . PHP_EOL;