forked from ruv1nce/42-exam_beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtab_mult.c
More file actions
76 lines (69 loc) · 914 Bytes
/
Copy pathtab_mult.c
File metadata and controls
76 lines (69 loc) · 914 Bytes
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
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int nb)
{
if (nb < 0)
{
ft_putchar('-');
if (nb == -2147483648)
{
ft_putchar('2');
nb += 2000000000;
}
nb *= (-1);
}
if (nb / 10 > 0)
ft_putnbr(nb / 10);
ft_putchar((nb % 10) + '0');
}
int ft_atoi(char *str)
{
int i;
int sum;
int posneg;
i = 0;
sum = 0;
posneg = 1;
while (str[i] <= ' ')
i++;
if (str[i] == '+')
i++;
else if (str[i] == '-')
{
posneg = -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
sum = sum * 10 + (str[i] - '0');
i++;
}
return (sum * posneg);
}
void print_mult(int n, int i)
{
ft_putnbr(i);
write(1, " x ", 3);
ft_putnbr(n);
write(1, " = ", 3);
ft_putnbr(n * i);
write(1, "\n", 1);
}
int main(int argc, char **argv)
{
int n;
int i;
if (argc == 2)
{
n = ft_atoi(argv[1]);
i = 1;
while (i <= 9)
{
print_mult(n, i);
i++;
}
}
}