write a program that estimates theprobability P that if N people are in a room,
ID: 3616126 • Letter: W
Question
write a program that estimates theprobability P that if N people are in a room, at least two of themhave the same birthday. By the same birthday, we mean the sameday and month (ignoring leap years), not the date of birth whichwould include the day, month and year.
The birthday paradox is that forrelatively small values of N, e.g. N=20, there is a surprising highprobability that two people in the same room happen to share thesame birthday. For N=30, the probability is very high.
Write a program to implement the birthday paradox. Your programwill use simulation to approximate the value of P for the givenvalue of N as follows:
· For yourprogram, assume that there are at most 100 people in the room.
· Yourprogram should read in N the number of people in the room and T thenumber of trials that you will run.
· For eachtrial, you should assign to each of the N people a random birthday(an integer between 0 and 364) and determine if at least two of thepeople have the same birthday.
· Do this Ttimes and count the number of trials C where two people have thesame birthday.
· Output thevalue N and the value of C/T which will be an estimate forP.
· Repeatthis experiment for N=10, N=15, N=20, N=25, and N=30.
Note: the larger the value you use for T, the more accurate C/Twill be for the probability P. I suggest that you use at least 1000for T.
Note: to generate a random integer B between 0 and 364 you canuse B = rand() mod 365
The interesting question about the birthday paradox is to findthe smallest value of N such that P is at least 0.5. That is,for this value of N there is a 50/50 chance that two people havethe same birthday. Before you run the experiment, guess whatthe value of N should be. Run your experiment and note that youshould find that this special value of N is less than 30.
Explanation / Answer
please rate - thanks #include #include using namespace std; int main() {int people[100],i,j,n,k,count=0,trials,yesno; bool dup; srand(time(0)); couttrials; do {do {coutn; if(n100) coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.