Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- double get_birthdays(int n);
- int main(int argc, char **argv) {
- for(int n = 2; n <= 80; n++){
- printf("%f\n", get_birthdays(n));
- }
- }
- double get_birthdays(int n) {
- srand(time(NULL));
- int birthdays[n];
- int b;
- int count = 0;
- for(int i = 0; i < 10000; i++){
- b = 0;
- for(int j = 0; j < n; j++){
- birthdays[j] = rand() % 365;
- }
- for(int j = 1; j < n; j++){
- if(birthdays[j] == birthdays[0]){
- b = 1;
- }
- }
- if(b){
- count++;
- }
- }
- return ((double) count)/10000.0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement