Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- const short N=6;
- bool czy_istnieje(int, int*, int); // prototyp funkcji
- void wypelnianie(int tab[])
- {
- int n;
- srand(time(nullptr));
- for(int i=0; i<N; ++i)
- {
- do
- {
- n = 1+rand()%49;
- } while(czy_istnieje(n, tab, i));
- tab[i] = n;
- }
- }
- void wypisz(int tab[])
- {
- for(int i=0; i<N; ++i)
- {
- cout << tab[i] << "\t";
- }
- }
- void bubblesort(int* tab)
- {
- for(int i = 0; i < N - 1; ++i)
- for(int j = 0; j < N - i - 1; ++j)
- if(tab[j] > tab[j + 1])
- swap(tab[j], tab[j + 1]); // zamiana
- }
- bool czy_istnieje(int a, int tab[], int n)
- {
- for(int i=0; i<n; ++i)
- {
- if(tab[i]==a) return 1;
- }
- return 0;
- }
- int main()
- {
- int tab[N];
- wypelnianie(tab);
- bubblesort(tab);
- wypisz(tab);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement