tanszek:oktatas:techcomm:statistical_properties
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tanszek:oktatas:techcomm:statistical_properties [2024/10/01 18:07] – [Frequency of Events] knehez | tanszek: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:// | ||
+ | |||
+ | <sxh c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #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; | ||
+ | if (simulate_twins()) { | ||
+ | at_least_one_girl++; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Calculate and print the result | ||
+ | double probability = (double)at_least_one_girl / SIMULATIONS * 100; | ||
+ | printf(" | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
**Example 5:**: https:// | **Example 5:**: https:// | ||
tanszek/oktatas/techcomm/statistical_properties.1727806046.txt.gz · Last modified: 2024/10/01 18:07 by knehez