Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. int *finish_it(char *rst, char *nb, int len)
  2. {
  3. int i;
  4.  
  5. i = len;
  6. while (i >= 0)
  7. {
  8. rst[i + 1] = nb[i];
  9. i--;
  10. }
  11. i = my_strlen(nb);
  12. while (i >= 0)
  13. {
  14. if (rst[i + 1] > 57)
  15. {
  16. rst[i + 1] = rst[i + 1] - 10;
  17. rst[i] = rst[i] + 1;
  18. }
  19. i--;
  20. }
  21. if (rst[0] < 47 || rst[0] > 58)
  22. rst[0] = '0';
  23. return (rst);
  24. }
  25.  
  26.  
  27. char *add(char *nb, char *nb2, int len, int len2)
  28. {
  29. char *rst;
  30. int i;
  31.  
  32. i = 0;
  33. rst = malloc(sizeof(char) * (len + 2));
  34. while (i != len + 1)
  35. {
  36. rst[i] = '0';
  37. i++;
  38. }
  39. while (len2 >= 0)
  40. {
  41. len2--;
  42. len--;
  43. rst[len + 1] = 48 + (nb[len] - 48) + (nb2[len2] - 48);
  44. }
  45. rst = finish_it(rst, nb, len);
  46. return (rst);
  47. }
  48.  
  49. int main(int ac, char **av)
  50. {
  51. char *rst;
  52. int nb;
  53. int nb2;
  54.  
  55. if (error(ac, av) == 84)
  56. return (84);
  57. nb = my_strlen(av[1]);
  58. nb2 = my_strlen(av[2]);
  59. if (nb >= nb2)
  60. rst = add(av[1], av[2], nb, nb2);
  61. else
  62. rst = add(av[2], av[1], nb2, nb);
  63. my_putstr(rst);
  64. my_putchar('\n');
  65. return (0);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement