Given two positive integers n and m. The task is to count number of parallelogram that can be formed of any size when n horizontal parallel lines intersect with m vertical parallel lines.
Input : n = 3, m = 2 Output : 3 2 parallelograms of size 1x1 and 1 parallelogram of size 2x1. Input : n = 5, m = 5 Output : 100
The idea is to use Combination, which state, number of ways to choose k items from given n items is given by nCr.
To form a parallelogram, we need two horizontal parallel lines and two vertical parallel lines. So, number of ways to choose two horizontal parallel lines are nC2 and number of ways to choose two vertical parallel lines are mC2. So, total number of possible parallelogram will be nC2 x mC2.
Below is C++ implementation of this approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to check if two given line segments intersect?
- Given n line segments, find if any two segments intersect
- Maximum number of 2x2 squares that can be fit inside a right isosceles triangle
- Number of Integral Points between Two Points
- Non-crossing lines to connect points in a circle
- n'th Pentagonal Number
- Count of parallelograms in a plane
- Paper Cut into Minimum Number of Squares
- Pizza cut problem (Or Circle Division by Lines)
- Minimum lines to cover all points
- Number of Triangles that can be formed given a set of lines in Euclidean Plane
- Slope of the line parallel to the line with the given slope
- Program for Point of Intersection of Two Lines
- Centered cube number
- Find number of diagonals in n sided convex polygon
- Centered Dodecagonal Number
- Number of unique rectangles formed using N unit squares
- Number of rectangles in N*M grid
- Check if two given circles touch or intersect each other
- Maximum number of squares that can fit in a right angle isosceles triangle
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : 29AjayKumar