Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #define n 7
- using namespace std;
- void output (int a[n]);
- int main()
- {
- int a[n] = {2, 5,-3, 4, 7,-7,-1};
- output(a);
- cout<<endl;
- for (int j=0 ; j<n ; j++)
- for (int i=0, t ; i<n-1 ; i++)
- if (a[i]>a[i+1] && a[i]>0 ||
- a[i]<a[i+1] && a[i]<0 && a[i+1]<0)
- {
- t = a[i+1];
- a[i+1] = a[i];
- a[i] = t;
- }
- output(a);
- }
- void output (int a[n])
- {
- for (int i=0 ; i<n ; i++)
- cout<< setw(2) <<a[i]<<" ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement