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

Write c code for the following i. (Birthday paradox revisited) Compute analytica

ID: 3820933 • Letter: W

Question

Write c code for the following i. (Birthday paradox revisited) Compute analytically the probability that at least two people in a group of N persons have the same birthday Hint: Let's say, N 4. Then, the number of possible birthday combinations for 4 persons is 365 x 365 x 365 x365 The number of possible cases where 4 persons have different birthdays (no one shares the same birthday) is 365 x 365 x 365 x 365 Therefore, the probability that all 4 persons have different birthdays is 365 364 363 362 365 365 365 365 probability that at least two people out of 4 have a same birthday is

Explanation / Answer

#include<stdio.h>

int main()
{
   //no of people
   int N, no_days_in_yr = 365,i;
   float diffrent_bday_peple = 1;
   float diffent_bday;
   //possible_bday_combination
   float possible_bday_combination(int n);

   printf("Enter the number of person: ");
   scanf("%d", &N);

   //calculate the probality of 4 persons have different bday is as below
   diffent_bday = possible_bday_combination(N) / diffrent_bday_peple;
     
   printf("Probability of %d people have different birth day = %f ", N, diffent_bday);
   printf("Prbability that at least two people out of %d have a same birth day = %.4f ", N, (1 - diffent_bday));
}

float possible_bday_combination(int N)
{
   float prod = 1;
   int   i, no_days_in_yr= 365 ,days_in_yr =365;
  
   //Probability that all 4 persons have different bdays is
   for (i = 0; i < N; i++)
   {
       prod *= (float)no_days_in_yr / days_in_yr;
       no_days_in_yr -= 1;
   }

   return prod;
}

---------------------------------------------------------------

//output1

Enter the number of person: 4
Probability of 4 people have different birth day = 0.983644
Prbability that at least two people out of 4 have a same birth day = 0.0164

//output2

Enter the number of person: 6
Probability of 6 people have different birth day = 0.959538
Prbability that at least two people out of 6 have a same birth day = 0.0405

-

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