Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. void multiply(ull* big, ull small)
  2. {
  3.     ull pr = 0;
  4.     for(int i = 0; i < 40; i++)
  5.     {
  6.         big[i] *= small;
  7.         big[i] += pr;
  8.         pr = big[i] / 10;
  9.         big[i] %= 10;
  10.     }
  11. }
  12. void add(ull* big1, ull* big2)
  13. {
  14.     bool pr = 0;
  15.     for(int i = 0; i < 40; i++)
  16.     {
  17.         //cout << big1[i]  << " ";
  18.         big1[i] = big1[i] + big2[i] + pr;
  19.        // cout << big1[i]  << " ";
  20.        // cout << "\n";
  21.         pr = big1[i] / 10;
  22.         big1[i] %= 10;
  23.     }
  24. }
  25. void subtract(ull* big1, ull* big2)
  26. {
  27.     ull non_zero = 40;
  28.     for(int i = 39; i >= 0; i--)
  29.     {
  30.         if(big1[i] != 0 || big2[i] != 0)
  31.         {
  32.             if(big1[i] >= big2[i])
  33.                 big1[i] -= big2[i];
  34.             else
  35.             {
  36.                 big1[non_zero]--;
  37.                 for(int j = non_zero - 1; j > i; j--)
  38.                 {
  39.                     big1[j] = 9;
  40.                 }
  41.                 big1[i] = big1[i] + 10 - big2[i];
  42.             }
  43.         }
  44.         //cout << big1[i] << " ";
  45.         if(big1[i] != 0)
  46.             non_zero = i;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement