Advertisement
SomeBody_Aplle

Untitled

Oct 1st, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "RUS");
  8.     int const n = 4;
  9.     int arr[n];
  10.  
  11.     int buf;
  12.  
  13.     for (int i = 0; i < n; i++)
  14.     {
  15.         cin >> arr[i];
  16.     }
  17.  
  18.     for (int i = 0; i < n - 1; i++)
  19.     {
  20.         for (int j = 0; j < n - i - 1; j++)
  21.         {
  22.             if (arr[j] > arr[j + 1])
  23.             {
  24.                 buf = arr[j];
  25.                 arr[j] = arr[j + 1];
  26.                 arr[j + 1] = buf;
  27.             }
  28.         }
  29.     }
  30.  
  31.     for (int i = 0; i < n; i++)
  32.     {
  33.         cout << arr[i] << " ";
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement