Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <iostream>
- #include <time.h>
- using namespace std;
- int z4(int n) {
- int countOfOld = 0, idx = 0, loops = 0, a[n] = {0};
- do {
- idx = rand() % n;
- if (a[idx] == 0) {
- a[idx] = 1;
- countOfOld++;
- }
- loops++;
- } while (countOfOld < n);
- return loops;
- }
- int main()
- {
- srand ( time(NULL) );
- int countOfMatchbox, matchesInBox, trying = 0;
- cout << "Podaj ilosc paczek zapalek: ";
- cin >> countOfMatchbox;
- cout << "Podaj ilosc zapalek w kazdej paczce: ";
- cin >> matchesInBox;
- for (int i = 0; i < countOfMatchbox; i++) {
- trying += z4(matchesInBox);
- }
- cout << "\nDla " << countOfMatchbox << " paczek, po " << matchesInBox;
- cout << " zapalek kazda \nsrednia ilosc losowan, po ktorych wszystkie zapalki beda spalone to: ";
- cout << trying / countOfMatchbox << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement