Advertisement
Guest User

Untitled

a guest
May 30th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a[50],n,i,j,temp;
  8. cout<<"Enter the size of array: ";
  9. cin>>n;
  10. cout<<"Enter the array elements: ";
  11.  
  12. for(i=0;i<n;++i)
  13. cin>>a[i];
  14.  
  15. for(i=1;i<n;++i)
  16. {
  17. for(j=0;j<(n-i);++j)
  18. if(a[j]>a[j+1])
  19. {
  20. temp=a[j];
  21. a[j]=a[j+1];
  22. a[j+1]=temp;
  23. }
  24. }
  25.  
  26. cout<<"Array after bubble sort:";
  27. for(i=0;i<n;++i)
  28. cout<<" "<<a[i];
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement