Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <iomanip>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12. bool wypierdalam;
  13. int n;
  14. cout<<"Podaj liczbe elementow: ";
  15. cin>>n;
  16. int *tab = new int [n];
  17. srand(time(NULL));
  18.  
  19. for(int i=0; i<n; i++)
  20. {
  21. tab[i] = rand()%100;
  22. cout<< tab[i] << " ";
  23. }
  24. cout << endl;
  25. for(int j=0; j<n; j++)
  26. {
  27. wypierdalam = true;
  28. for (int i=0; i<n; i++)
  29. {
  30. if(tab[i]>tab[i+1])
  31. {
  32. swap(tab[i],tab[i+1]);
  33. wypierdalam = false;
  34. }
  35. cout << setw(4) << tab[i];
  36. }
  37. cout << endl;
  38. if (wypierdalam == true) break;
  39. }
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement