forked from ALX-SE-Algorithmia/Demo-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_calc.c
67 lines (61 loc) · 979 Bytes
/
basic_calc.c
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
#include "calc.h"
/**
* add - adds two numbers
* @a: first number
* @b: second number
* Return: sum of a and b
*/
double add(double a, double b)
{
return (a + b);
}
/**
* sub - subtracts two numbers
* @a: first number
* @b: second number
* Return: difference of a and b
*/
double sub(double a, double b)
{
return (a - b);
}
/**
* mul - multiplies two numbers
* @a: first number
* @b: second number
* Return: product of a and b
*/
double mul(double a, double b)
{
return (a * b);
}
/**
* division - divides two numbers
* @a: first number
* @b: second number
* Return: quotient of a / b
*/
double division(double a, double b)
{
if (b == 0)
{
printf("Error: Division by 0.\n");
exit(EXIT_FAILURE);
}
return (a / b);
}
/**
* mod - modulo of two numbers
* @a: first number
* @b: second number
* Return: modulus of a % b
*/
int mod(int a, int b)
{
if (b == 0)
{
printf("Error: Modulo by 0.\n");
exit(EXIT_FAILURE);
}
return (a % b);
}