suppose that people enter an empty room one by one until a pair of people share a birthday. on average, how many people will enter before there is a match?(adsbygoogle = window.adsbygoogle || []).push({});

my approach was to have 200 people entering; the birthdays of the first 100 people were stored into one array while the second 100 people's birthdays were stored in a different array. then i compared these arrays until they had the same value. my problems are -- 1) i'm not sure if my code is right for the approach i have, 2) i want to get an average so would the best way be move what i already have inside another for loop, 3) should the value be the same every time i execute it?

Code (Text):

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int figure(int s[], int p[]);

int main(){

const int MAX_SIZE = 100;

int p[MAX_SIZE] = {0};

int s[MAX_SIZE] = {0};

srand(time(0));

for (int i = 0; i < MAX_SIZE; i++){

s[i] = rand()%364;

}

for (int k = 0; k < MAX_SIZE; k++){

p[k] = rand()%364;

}

cout << figure(s,p);

}

int figure(int s[], int p[]){

for (int j = 0; j < 100; j++){

if (s[j] == p[j])

return j;

break;

}

}

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Birthday probability

**Physics Forums | Science Articles, Homework Help, Discussion**