Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please provide working code that can be understood. Thanks! The Birthday Problem

ID: 3535682 • Letter: P

Question



Please provide working code that can be understood.


Thanks!

The Birthday Problem The Birthday Problem is stated as follows: if there is a group of n people in a room, what is the probability that two or more of them have the same birthday? It is possible to determine the answer to this question by simulation. Write a function that calculates the probability that two or more of n people will have the same birthday, where n is a calling argument. (Hint: To do this, the function should create an array of size n and generate n birthdays in the range 1 to 365 randomly. It should then check to see if any of the n birthdays are identical. The function should perform this experiment at least 5000 times and calculate the fraction of those times in which two or more people had the same birthday.) Write a test program that calculates and prints out the probability that two or more of n people will have the same birthday for n = 2, 3,..., 40.

Explanation / Answer

You will need to start with a loop that goes 5000 times and will contain the meat of your program. Inside, you can generate random numbers from 1-365 to fill an array which holds the birthdays of the people. Then, you could have a loop that goes 1-365 and counts the number of occurrences of the particular day with another loop.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote