Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define MINUS 2
- int main()
- {
- int n;
- int tempn;
- int count = 0;
- int sing = 1;
- char* str;
- char* curstr;
- int ch0 = (int)'0';
- std::cout << "Input number, PLEASE: ";
- std::cin >> n;
- if (n < 0){
- n *= -1;
- sing++;
- }
- tempn = n;
- while(tempn > 0) {
- tempn = tempn / 10;
- count++;
- }
- tempn = n;
- str = new char[count+sing];
- curstr = str + sing - 1;
- for (int i = count-1; i >= 0; i--) {
- curstr[i] = char(ch0 + tempn%10);
- tempn = tempn/10;
- }
- if(sing == MINUS) {
- str[0] = '-';
- }
- str[count + sing - 1] = '\0';
- std::cout << "str = " << str << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement