Advertisement
MeehoweCK

Untitled

Jan 6th, 2024
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int N{ 6 };
  6.  
  7. void wprowadz_liczby(int* tab) {
  8.     cout << "Wprowadz " << N << " liczb: ";
  9.     for (int i = 0; i < N; ++i) {
  10.         cin >> tab[i];
  11.     }
  12. }
  13.  
  14. void sortuj(int* tab) {
  15.     for (int i = 0; i < N - 1; ++i) {
  16.         for (int j = 0; j < N - 1 - i; ++j) {
  17.             if (tab[j] < tab[j + 1]) {
  18.                 swap(tab[j], tab[j + 1]);
  19.             }
  20.         }
  21.     }
  22.     cout << "Posortowano tablice\n";
  23. }
  24.  
  25. void wypisz_tablice(int* tab) {
  26.     cout << "Tablica:\t";
  27.     for (int i = 0; i < N; ++i) {
  28.         cout << tab[i] << '\t';
  29.     }
  30.     cout << endl;
  31. }
  32.  
  33. int main() {
  34.     int tab[N];
  35.     wprowadz_liczby(tab);
  36.     wypisz_tablice(tab);
  37.     sortuj(tab);
  38.     wypisz_tablice(tab);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement