ostapdontstop

Untitled

Dec 7th, 2017
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n=7, a[n] = {2,5,-3,4,7,-7,-1};
  7.  
  8.     for (int i=0 ; i<n ; i++)
  9.         cout<<a[i]<<"  ";
  10.     cout<<endl;
  11.  
  12.     for (int j=0 ; j<n ; j++)
  13.         for (int i=0, t ; i<n-1 ; i++)
  14.             if (a[i]>a[i+1] && a[i]>0 ||
  15.             a[i]<a[i+1] && a[i]<0 && a[i+1]<0) {
  16.                 t = a[i+1];
  17.                 a[i+1] = a[i];
  18.                 a[i] = t;
  19.             }
  20.     for (int i=0 ; i<n ; i++)
  21.         cout<<a[i]<<"  ";
  22.  
  23.     return 0;
  24. }
RAW Paste Data