Advertisement
Taraxacum

Integer_plus_1

Oct 24th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define MAX_SIZE 64
  6.  
  7. int main(int argc, char const* argv[])
  8. {
  9.     char buffer[MAX_SIZE] = { '0' };
  10.     char* ptr = buffer;
  11.     ptr++;
  12.  
  13.     cout << "Give a Non-Negative Number: " << endl;
  14.     cin >> ptr;
  15.  
  16.     int i = 0;
  17.     while (buffer[++i] != '\0')
  18.         ;
  19.  
  20.     buffer[--i]++;
  21.  
  22.     while (i > 0) {
  23.         if (buffer[i] > '9') {
  24.             buffer[i] -= 10;
  25.             buffer[i - 1] += 1;
  26.             i--;
  27.         } else {
  28.             break;
  29.         }
  30.     }
  31.  
  32.     if (buffer[0] == '0') {
  33.         cout << ptr << endl;
  34.     } else {
  35.         cout << buffer << endl;
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement