Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- int num{ 1234567890 };
- int newNum{ 0};
- int mul{ 1 };
- bool operation{true};
- /*while (num)
- {
- int digit{ (num % 10) * mul };
- newNum += (operation ? digit * 10 : digit / 10);
- num /= 10;
- mul *= 10;
- operation = !operation;
- }
- */
- //for (mul = 1, operation = true; num; num /= 10, mul *= 10, operation = !operation)
- //{
- // int digit{ (num % 10) * mul };
- // newNum += (operation ? digit * 10 : digit / 10);
- //}
- int digit{ 0 };
- for (mul = 1, operation = true; digit = ((num % 10) * mul), num; newNum += (operation ? digit * 10 : digit / 10), num /= 10, mul *= 10, operation = !operation);
- std::cout << newNum << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement