Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- bool czyUnikalna(int liczba, int liczby[], int podane)
- {
- int i = 0;
- while(i < podane)
- {
- if (liczby[i] == liczba)
- return false;
- i++;
- };
- return true;
- }
- int losowanie(int min, int max)
- {
- return rand() % (max-min+1) + min;
- }
- int main()
- {
- srand(time(NULL));
- cout << "Podaj 10 liczb: " << endl;
- int liczby[10];
- int podane = 0;
- do
- {
- cin >> liczba;
- if (czyUnikalna(liczba,liczby,podane)) //sprawdza czy w tablicy na indeksach 0 do i<pobrane nie ma juz wartości liczba
- {
- liczby[podane] = liczba;
- podane++;
- }
- else
- {
- // napisz, ze liczba nie jest unikalna
- }
- }while(podane<10);
- int wylosowaneIndeksy[8]; //tablica na indeksy już wylosowane
- podane = 0;
- do
- {
- int los = losowanie(0, 9);
- if(czyUnikalna(los, wylosowaneIndeksy, podane)) //sprawdza
- {
- wylosowaneIndeksy[podane] = los;
- cout << liczby[los] << endl;
- podane++;
- }
- }while(podane<8);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement