Guest User

Untitled

a guest
Jun 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1.     //Find the necessary number of operations (highest number of digits)
  2.     int calcCount;
  3.     if (currentSize > x.currentSize)
  4.         calcCount = currentSize;
  5.     else
  6.         calcCount = x.currentSize;
  7.     //make the new return array
  8.     char sum[100];
  9.     //perform the calculations starting at the least significant digit
  10.     int result;
  11.     int carry = 0;
  12.     int finalNull;
  13.     cout << "calcCount is " << calcCount << endl;
  14.     for (int i = 0; i < calcCount; i++) {
  15.         int result = static_cast<int>(number[MAXSIZE - i]) + static_cast<int>(x.number[MAXSIZE - i] + carry);
  16.         if (carry != 0)
  17.             carry = 0;
  18.         if (result > 10) {
  19.             result = result % 10;
  20.             carry = 1;
  21.         }
  22.         sum[MAXSIZE - i] = result;
  23.         finalNull = i + 1;
  24.     }
  25.     sum[MAXSIZE - finalNull] = '\n';
  26.     return sum;
Add Comment
Please, Sign In to add comment