Advertisement
mhdew

Q2 b

Dec 2nd, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin>>n;
  9.     int a[n+2];
  10.     bool flag[111111];
  11.     for(int i=0;i<n;i++){
  12.         cin>>a[i];
  13.     }
  14.  
  15.     for(int i=0;i<n-1;i++){
  16.         for(int j=i+1;j<n;j++){
  17.             if(a[i]>a[j]){
  18.                 swap(a[i],a[j]);
  19.             }
  20.         }
  21.     }
  22.  
  23.     for(int i=0;i<n;i++){
  24.         cout<<a[i]<<" ";
  25.     }
  26.     cout<<endl;
  27.  
  28.     for(int i=0;i<n-1;i++){
  29.         for(int j=i+1;j<n;j++){
  30.             if(a[i]<a[j]){
  31.                 swap(a[i],a[j]);
  32.             }
  33.         }
  34.     }
  35.  
  36.     for(int i=0;i<n;i++){
  37.         cout<<a[i]<<" ";
  38.     }
  39.     cout<<endl;
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement