Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #define MINUS 2
  3. int main()
  4. {
  5.     int n;
  6.     int tempn;
  7.     int count = 0;
  8.     int sing = 1;
  9.     char* str;
  10.     char* curstr;
  11.     int ch0 = (int)'0';
  12.     std::cout << "Input number, PLEASE: ";
  13.     std::cin >> n;
  14.     if (n < 0){
  15.         n *= -1;
  16.         sing++;
  17.     }
  18.     tempn = n;
  19.     while(tempn > 0) {
  20.         tempn = tempn / 10;
  21.         count++;
  22.     }
  23.     tempn = n;
  24.     str = new char[count+sing];
  25.     curstr = str + sing - 1;
  26.     for (int i = count-1; i >= 0; i--) {
  27.         curstr[i] = char(ch0 + tempn%10);
  28.         tempn = tempn/10;
  29.     }
  30.     if(sing == MINUS) {
  31.         str[0] = '-';
  32.     }
  33.     str[count + sing - 1] = '\0';
  34.     std::cout << "str = " << str << std::endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement