Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. double get_birthdays(int n);
  7.  
  8. int main(int argc, char **argv) {
  9.   for(int n = 2; n <= 80; n++){
  10.     printf("%f\n", get_birthdays(n));
  11.   }
  12. }
  13.  
  14. double get_birthdays(int n) {
  15.   srand(time(NULL));
  16.   int birthdays[n];
  17.   int b;
  18.   int count = 0;
  19.   for(int i = 0; i < 10000; i++){
  20.     b = 0;
  21.     for(int j = 0; j < n; j++){
  22.       birthdays[j] = rand() % 365;
  23.     }
  24.     for(int j = 1; j < n; j++){
  25.       if(birthdays[j] == birthdays[0]){
  26.         b = 1;
  27.       }
  28.     }
  29.     if(b){
  30.       count++;
  31.     }
  32.   }
  33.   return ((double) count)/10000.0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement