Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. int z4(int n) {
  7. int countOfOld = 0, idx = 0, loops = 0, a[n] = {0};
  8. do {
  9. idx = rand() % n;
  10. if (a[idx] == 0) {
  11. a[idx] = 1;
  12. countOfOld++;
  13. }
  14. loops++;
  15. } while (countOfOld < n);
  16. return loops;
  17. }
  18.  
  19. int main()
  20. {
  21. srand ( time(NULL) );
  22. int countOfMatchbox, matchesInBox, trying = 0;
  23.  
  24. cout << "Podaj ilosc paczek zapalek: ";
  25. cin >> countOfMatchbox;
  26. cout << "Podaj ilosc zapalek w kazdej paczce: ";
  27. cin >> matchesInBox;
  28.  
  29.  
  30. for (int i = 0; i < countOfMatchbox; i++) {
  31. trying += z4(matchesInBox);
  32. }
  33. cout << "\nDla " << countOfMatchbox << " paczek, po " << matchesInBox;
  34. cout << " zapalek kazda \nsrednia ilosc losowan, po ktorych wszystkie zapalki beda spalone to: ";
  35. cout << trying / countOfMatchbox << endl;
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement