Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int *finish_it(char *rst, char *nb, int len)
- {
- int i;
- i = len;
- while (i >= 0)
- {
- rst[i + 1] = nb[i];
- i--;
- }
- i = my_strlen(nb);
- while (i >= 0)
- {
- if (rst[i + 1] > 57)
- {
- rst[i + 1] = rst[i + 1] - 10;
- rst[i] = rst[i] + 1;
- }
- i--;
- }
- if (rst[0] < 47 || rst[0] > 58)
- rst[0] = '0';
- return (rst);
- }
- char *add(char *nb, char *nb2, int len, int len2)
- {
- char *rst;
- int i;
- i = 0;
- rst = malloc(sizeof(char) * (len + 2));
- while (i != len + 1)
- {
- rst[i] = '0';
- i++;
- }
- while (len2 >= 0)
- {
- len2--;
- len--;
- rst[len + 1] = 48 + (nb[len] - 48) + (nb2[len2] - 48);
- }
- rst = finish_it(rst, nb, len);
- return (rst);
- }
- int main(int ac, char **av)
- {
- char *rst;
- int nb;
- int nb2;
- if (error(ac, av) == 84)
- return (84);
- nb = my_strlen(av[1]);
- nb2 = my_strlen(av[2]);
- if (nb >= nb2)
- rst = add(av[1], av[2], nb, nb2);
- else
- rst = add(av[2], av[1], nb2, nb);
- my_putstr(rst);
- my_putchar('\n');
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement