MeehoweCK

Untitled

Apr 5th, 2023
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 5;
  6.  
  7. void bubblesort(int* tablica)
  8. {
  9.     for(int i = 0; i < N - 1; ++i)
  10.         for(int j = 0; j < N - i - 1; ++j)
  11.             if(tablica[j] > tablica[j + 1])
  12.                 swap(tablica[j], tablica[j + 1]);
  13. }
  14.  
  15. void wypisz(int* tablica)
  16. {
  17.     for(int i = 0; i < N; ++i)
  18.         cout << tablica[i] << '\t';
  19.     cout << endl;
  20. }
  21.  
  22. int main()
  23. {
  24.     int tablica[5] = {25, 17, 33, 10, 16};
  25.     wypisz(tablica);
  26.     bubblesort(tablica);
  27.     wypisz(tablica);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment