Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. void add ( const char a[], const char b[], char res[]);
  2. {
  3. int digita = strlen(a);
  4. int digitb = strlen(b);
  5. int suma = 0;
  6. int sumb = 0;
  7.  
  8. for(int i = 0; i < digita; i ++)
  9. {
  10. suma *= 10;
  11. suma += (a[i] - '0');
  12.  
  13. }
  14. for(int x = 0; x < digitb; x ++)
  15. {
  16. sumb *= 10;
  17. sumb += (b[x] - '0');
  18.  
  19. }
  20.  
  21. int sum = suma + sumb;
  22. char res[20];
  23. sprintf(res, "%d\n", sum);
  24. printf("%s\n", res);
  25. }
  26.  
  27. void sub ( const char a[], const char b[], char res[]);
  28. {
  29. int digita = strlen(a);
  30. int digitb = strlen(b);
  31. int suma = 0;
  32. int sumb = 0;
  33.  
  34. for(int i = 0; i < digita; i ++)
  35. {
  36. suma *= 10;
  37. suma += (a[i] - '0');
  38.  
  39. }
  40. for(int x = 0; x < digitb; x ++)
  41. {
  42. sumb *= 10;
  43. sumb += (b[x] - '0');
  44.  
  45. }
  46.  
  47.  
  48. int diff = suma - sumb;
  49. char res2[20];
  50. sprintf(res2, "%d\n", diff);
  51. printf("%s\n", res2);
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement