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_juz_jest(short liczba, short* tablica, short n)
- {
- for(short i = 0; i < n; ++i)
- if(liczba == tablica[i])
- return true;
- return false;
- }
- void wypelnij_tablice(short* tablica)
- {
- srand(time(nullptr));
- short losowana;
- for(short i = 0; i < N; ++i)
- {
- do
- {
- losowana = 1 + rand() % 49;
- } while(czy_juz_jest(losowana, tablica, i));
- tablica[i] = losowana;
- }
- }
- void wypisz_tablice(short* tablica)
- {
- for(short i = 0; i < N; ++i)
- cout << tablica[i] << '\t';
- cout << endl;
- }
- int main()
- {
- short tablica[6];
- wypelnij_tablice(tablica);
- wypisz_tablice(tablica);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement