Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- char* numToStr(int num, char* str)
- {
- char tmp{};
- for (size_t i{ 0 }; *(str + i) = (num > 0 ? '0' + (num % 10) : 0); num /= 10, ++i);
- for (size_t h{ 0 }, t{ strlen(str) - 1 }; h < t; ++h, --t)
- {
- tmp = *(str + h);
- *(str + h) = *(str + t);
- *(str + t) = tmp;
- }
- return str;
- }
- int strToNum(const char* str)
- {
- int num{ 0 };
- for (; *str; num *= 10, num += *str++ - '0');
- return num;
- }
- int main()
- {
- char str[10];
- std::cout << numToStr(26907, str) << '\n';
- std::cout << strToNum(str) << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement