Advertisement
avr39ripe

change4DigitNumMega

Oct 6th, 2020 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     int num{ 1234567890 };
  6.     int newNum{ 0};
  7.     int mul{ 1 };
  8.     bool operation{true};
  9.  
  10.     /*while (num)
  11.     {
  12.         int digit{ (num % 10) * mul };
  13.  
  14.         newNum += (operation  ? digit * 10 :  digit / 10);
  15.         num /= 10;
  16.         mul *= 10;
  17.        
  18.         operation = !operation;
  19.     }
  20. */
  21.  
  22.     //for (mul = 1, operation = true; num; num /= 10, mul *= 10, operation = !operation)
  23.     //{
  24.     //  int digit{ (num % 10) * mul };
  25.  
  26.     //  newNum += (operation ? digit * 10 : digit / 10);
  27.     //}
  28.    
  29.     int digit{ 0 };
  30.     for (mul = 1, operation = true; digit = ((num % 10) * mul), num; newNum += (operation ? digit * 10 : digit / 10), num /= 10, mul *= 10, operation = !operation);
  31.  
  32.     std::cout << newNum << '\n';
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement