Advertisement
ostapdontstop

Untitled

Dec 8th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #define n 7
  4. using namespace std;
  5.  
  6. void output (int a[n]);
  7.  
  8. int main()
  9. {
  10.     int a[n] = {2, 5,-3, 4, 7,-7,-1};
  11.  
  12.     output(a);
  13.  
  14.     cout<<endl;
  15.  
  16.     for (int j=0 ; j<n ; j++)
  17.         for (int i=0, t ; i<n-1 ; i++)
  18.             if (a[i]>a[i+1] && a[i]>0 ||
  19.                 a[i]<a[i+1] && a[i]<0 && a[i+1]<0)
  20.             {
  21.                 t = a[i+1];
  22.                 a[i+1] = a[i];
  23.                 a[i] = t;
  24.             }
  25.     output(a);
  26. }
  27.  
  28. void output (int a[n])
  29. {
  30.     for (int i=0 ; i<n ; i++)
  31.         cout<< setw(2) <<a[i]<<"  ";
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement