Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- bool czy_jest(int liczba, int* tab, int n)
- {
- for(int i = 0; i < n; ++i)
- if(tab[i] == liczba)
- return true;
- return false;
- }
- void wyswietl(int* tab, int n)
- {
- for(int i = 0; i < n; ++i)
- cout << tab[i] << '\t';
- cout << endl;
- }
- void bubblesort(int* tab, int n)
- {
- for(int i = 0; i < 6; ++i)
- for(int j = 0; j < 5 - i; ++j)
- if(tab[j] > tab[j + 1])
- swap(tab[j], tab[j + 1]);
- }
- int main()
- {
- srand(time(nullptr));
- int tab[6], losowana;
- for(int i = 0; i < 6; ++i)
- {
- do
- {
- losowana = 1 + rand() % 49;
- } while(czy_jest(losowana, tab, i));
- tab[i] = losowana;
- }
- bubblesort(tab, 6);
- wyswietl(tab, 6);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement