Advertisement
nicuvlad76

Untitled

Nov 19th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #define N 1005
  4. using namespace std;
  5. ifstream fin("bac.txt");
  6. /**
  7. sortare prin bule
  8. */
  9. int main()
  10. {
  11. int a[N],n,i,j,aux;
  12. cin>>n;
  13. for(int i=1;i<=n;i++)cin>>a[i];
  14.  
  15. ///sortarea
  16. bool ord=0;
  17. while(ord==0)
  18. {
  19. ord=1;
  20. for(i=1;i<n;i++)
  21. if(a[i]>a[i+1])
  22. {
  23. aux=a[i];a[i]=a[i+1]; a[i+1]=aux;
  24. ord=0;
  25. }
  26. }
  27.  
  28. for(int i=1;i<=n;i++)
  29. cout<<a[i]<<" ";
  30.  
  31. return 0;
  32. }
  33.  
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement