Advertisement
krylovilya

Untitled

Nov 19th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "Russian");
  8.     int x;
  9.     cout << "Введите число: ";
  10.     cin >> x;
  11.     int y, z;
  12.     y = x % 10;
  13.     x /= 10;
  14.     while (x != 0)
  15.     {
  16.         if (x % 10 >= y % 10)
  17.             y = y * 10 + x % 10;
  18.         else
  19.         {
  20.             z = 0;
  21.             while (x % 10 < y % 10 && y > 0)
  22.             {
  23.                 z = z * 10 + y % 10;
  24.                 y /= 10;
  25.             }
  26.             y = y * 10 + x % 10;
  27.             while (z != 0)
  28.             {
  29.                 y = y * 10 + z % 10;
  30.                 z /= 10;
  31.             }
  32.         }
  33.         x /= 10;
  34.     }
  35.     cout << endl << "результат: " << y << endl;
  36.     system("pause");
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement