-
Notifications
You must be signed in to change notification settings - Fork 105
/
tab_mult.c
57 lines (51 loc) · 776 Bytes
/
tab_mult.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
#include <unistd.h>
int ft_atoi(char *str)
{
int result;
int sign;
result = 0;
sign = 1;
while (*str == ' ' || (*str >= 9 && *str <= 13))
str++;
if (*str == '+')
str++;
while (*str >= '0' && *str <= '9')
{
result = result * 10 + *str - '0';
str++;
}
return (sign * result);
}
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int nb)
{
if (nb / 10 > 0)
ft_putnbr(nb / 10);
ft_putchar(nb % 10 + '0');
}
int main(int argc, char *argv[])
{
int i;
int nbr;
if (argc != 2)
write(1, "\n", 1);
else
{
i = 1;
nbr = ft_atoi(argv[1]);
while (i <= 9 && nbr <= 238609183)
{
ft_putnbr(i);
write(1, " x ", 3);
ft_putnbr(nbr);
write(1, " = ", 3);
ft_putnbr(i * nbr);
write(1, "\n", 1);
i += 1;
}
}
return (0);
}