Rule of Product
In combinatorics, the rule of product is a principle for counting the number of ways to perform several tasks independently. It states that if one task can be done in m ways and another task can be done in n ways, then there are m x n ways to do both tasks.
For example, if there are 3 choices for appetizer and 5 choices for entree, then there are:
3 x 5 = 15 total meal combinations
More generally, if task A can be done in m ways and task B can be done in n ways, the total number of ways to do A and B is:
m x n
Java example  counting bipartite matchings:


C++ example  number of binary strings:


Python example  password permutations:


The rule of product is fundamental for counting combinatorial possibilities.
The Rule of Product is a fundamental concept in combinatorics, and it can be applied in various areas, including computer science and programming.
The Rule of Product, also known as the multiplication principle, is used to determine the number of possible outcomes in a sequence of events. If there are ( n ) ways to perform the first event and ( m ) ways to perform the second event, then there are ( n \times m ) ways to perform both events in sequence.
For example, if you have 3 shirts and 4 trousers, the number of different outfits you can wear is ( 3 \times 4 = 12 ).
Solution
Below are the code snippets to calculate the product of possibilities for two events in Java, C++, and Python.
Java


C++


Python


These code snippets accept two integers representing the number of ways to perform two different events and return the total number of outcomes by applying the Rule of Product.