I have been given an assignment to create a Fortran 90 program that calculates how many people are needed so that the probability of two or more people having the same birthday becomes 90%.
I would like to define variables as follows:
- P2 = probability of having at least 2 people of the same birthday among n people
- P1 = probability that all n people have different birthdays
- P2= 1- P1
- P1 = (364/365)(363/365)(362/365).... ((365-n-1)/365)
Edited: This is the code I have tried to compose:
program birth1
implicit none
integer:: n
real(8):: P1, P2
n=1
P1 = 1
do
p1 = P1 * ((365.0d0 -n +1)/365.0d0)
If (P1 <= 0.1) exit
n= n+1
end do
write (*,*) n
stop
end program birth1
This code has worked and I got 41 as the output. Thank you.