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()
- {
- return(rand () % 10) + 1;
- }
- int main()
- {
- srand( time(0) );
- int wylosowane[5];
- int wylosowanych = 0;
- do
- {
- int liczba = wylosuj();
- if( czy_byla_wylosowana(liczba, wylosowane, wylosowanych) == false)
- {
- wylosowane[wylosowanych] = liczba;
- wylosowanych++;
- }
- } while (wylosowanych < 5);
- wylosowanych = 0;
- do
- {
- cout << wylosowane[wylosowanych] << endl;
- wylosowanych++;
- }while (wylosowanych < 5 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment