grodek118

Losowanie wprowadzonych liczb

Aug 25th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. bool czy_byla_wylosowana (int iLiczba, int tab[], int ile)
  8. {
  9. if( ile <= 0)
  10. return false;
  11.  
  12. int i = 0;
  13. do
  14. {
  15. if (tab [i] == iLiczba)
  16. return true;
  17. i++;
  18. } while ( i < ile );
  19.  
  20. return false;
  21. }
  22.  
  23. int wylosuj(int min, int max)
  24. {
  25. return(rand () % max) + min;
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31. srand( time(0) );
  32. cout << "Podaj 3 losowe liczby" << endl;
  33. int tablica[3];
  34. int wylosowane = 0;
  35. cin >> tablica[0];
  36. cin >> tablica[1];
  37. cin >> tablica[2];
  38. cout << endl;
  39.  
  40. do
  41. {
  42. int liczba = wylosuj(0, 2);
  43. if(!czy_byla_wylosowana(liczba, tablica, wylosowane))
  44. {
  45. cout << tablica[liczba] << endl;
  46. wylosowane++;
  47. }
  48. } while(wylosowane < 2 );
  49.  
  50. return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment