Advertisement
MeehoweCK

Untitled

Nov 16th, 2020
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. bool czy_jest(int liczba, int* tab, int n)
  8. {
  9.     for(int i = 0; i < n; ++i)
  10.         if(tab[i] == liczba)
  11.             return true;
  12.     return false;
  13. }
  14.  
  15. void wyswietl(int* tab, int n)
  16. {
  17.     for(int i = 0; i < n; ++i)
  18.         cout << tab[i] << '\t';
  19.     cout << endl;
  20. }
  21.  
  22. void bubblesort(int* tab, int n)
  23. {
  24.     for(int i = 0; i < 6; ++i)
  25.         for(int j = 0; j < 5 - i; ++j)
  26.             if(tab[j] > tab[j + 1])
  27.                 swap(tab[j], tab[j + 1]);
  28. }
  29.  
  30. int main()
  31. {
  32.     srand(time(nullptr));
  33.     int tab[6], losowana;
  34.  
  35.     for(int i = 0; i < 6; ++i)
  36.     {
  37.         do
  38.         {
  39.             losowana = 1 + rand() % 49;
  40.         } while(czy_jest(losowana, tab, i));
  41.         tab[i] = losowana;
  42.     }
  43.     bubblesort(tab, 6);
  44.     wyswietl(tab, 6);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement