-
Notifications
You must be signed in to change notification settings - Fork 0
/
do-op.c
86 lines (75 loc) · 1.51 KB
/
do-op.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Calculator for one mathematical operation with integers (+,-,*,/,%)
// here are the functions described in the header "pisice.h"
#include "piscine.h"
void plus(int a, int b){
ft_putnbr(a + b);
}
void minus(int a, int b){
ft_putnbr(a - b);
}
void mult(int a, int b){
ft_putnbr(a * b);
}
void divis(int a, int b){
if (b == 0)
{
ft_putstr("Stop: division by zero");
}
else
{
int res;
res = a / b;
ft_putnbr(res);
}
}
void mod(int a, int b){
if (b == 0)
{
ft_putstr("Stop: modul by zero");
}
else
ft_putnbr(a % b);
}
void maker(int a, char action, int b)
{
if (!a || !b || !action)
action = '0';
switch (action)
{
case ('+'):
plus(a, b);
break;
case ('-'):
minus(a, b);
break;
case ('*'):
mult(a, b);
break;
case ('/'):
divis(a, b);
break;
case ('%'):
mod(a, b);
break;
default:
ft_putnbr(0);
break;
}
}
void ft_mathematical_action(char **argv)
{
int a;
int b;
char action;
action = argv[2][0];
a = ft_atoi(argv[1]);
b = ft_atoi(argv[3]);
maker (a, action, b);
}
int main (int argc, char **argv)
{
if (argc != 4){
return (0);
}
ft_mathematical_action(argv);
}