Advertisement
borsha06

bubble

Apr 11th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,i,j,k,a[1000],temp;
  6.     cin>>n;
  7.     for(i=1; i<=n; i++)
  8.     {
  9.         cin>>a[i];
  10.     }
  11.     for(i=1; i<=n; i++)
  12.     {
  13.         for(j=i+1; j<=n; j++)
  14.         {
  15.             if(a[i] > a[j])
  16.             {
  17.                 temp = a[i];
  18.                 a[i] = a[j];
  19.                 a[j] = temp;
  20.  
  21.             }
  22.         }
  23.  
  24.     }
  25.     for(i=1; i<=n; i++)
  26.     {
  27.         cout<<a[i]<<endl;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement