Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- bool czy_byla_wylosowana (int iLiczba, int tab[], int ile)
- {
- if( ile <= 0)
- return false;
- int i = 0;
- do
- {
- if (tab [i] == iLiczba)
- return true;
- i++;
- } while ( i < ile );
- return false;
- }
- int wylosuj(int min, int max)
- {
- return(rand () % max) + min;
- }
- int main()
- {
- srand( time(0) );
- cout << "Podaj 3 losowe liczby" << endl;
- int tablica[3];
- int wylosowane = 0;
- cin >> tablica[0];
- cin >> tablica[1];
- cin >> tablica[2];
- cout << endl;
- do
- {
- int liczba = wylosuj(0, 2);
- if(!czy_byla_wylosowana(liczba, tablica, wylosowane))
- {
- cout << tablica[liczba] << endl;
- wylosowane++;
- }
- } while(wylosowane < 2 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment