User Tools

Site Tools


tanszek:oktatas:techcomm:statistical_properties

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tanszek:oktatas:techcomm:statistical_properties [2024/10/01 18:07] – [Frequency of Events] kneheztanszek:oktatas:techcomm:statistical_properties [2024/10/04 19:17] (current) knehez
Line 76: Line 76:
  
 **Example 4:**:  Woman is expecting twins, what is the probability that one of the children will be a girl? **Example 4:**:  Woman is expecting twins, what is the probability that one of the children will be a girl?
 +
 +Create sets containing all the possibilities.   
 +
 +Try the following c code here: https://www.onlinegdb.com/online_c_compiler and examine the results.
 +
 +<sxh c>
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <time.h>
 +
 +#define SIMULATIONS 1000
 +
 +// Function to simulate the birth of twins
 +int simulate_twins() {
 +    // Randomly determine the gender of the twins (0 = boy, 1 = girl)
 +    int first_child = rand() % 2;
 +    int second_child = rand() % 2;
 +
 +    // Return 1 if there is at least one girl, otherwise 0
 +    return (first_child == 1 || second_child == 1);
 +}
 +
 +int main() {
 +    int at_least_one_girl = 0;
 +
 +    // Initialize the random number generator
 +    srand(time(0));
 +
 +    // Simulate 1000 pairs of twins
 +    for (int i = 0; i < SIMULATIONS; i++) {
 +        if (simulate_twins()) {
 +            at_least_one_girl++;
 +        }
 +    }
 +
 +    // Calculate and print the result
 +    double probability = (double)at_least_one_girl / SIMULATIONS * 100;
 +    printf("In %.2f%% of cases, there is at least one girl in the twin pair.\n", probability);
 +
 +    return 0;
 +}
 +</sxh>
 +
  
 **Example 5:**: https://en.wikipedia.org/wiki/Monty_Hall_problem **Example 5:**: https://en.wikipedia.org/wiki/Monty_Hall_problem
  
tanszek/oktatas/techcomm/statistical_properties.1727806046.txt.gz · Last modified: 2024/10/01 18:07 by knehez