Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively | C ++ Program to count number of rectangles formed by N lines parallel to X axis M lines parallel to Y axis ; Function to calculate number of rectangles ; Total number of ways to select two lines parallel to X axis ; Total number of ways to select two lines parallel to Y axis ; Total number of rectangles ; Driver Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int count_rectangles ( int N , int M ) { int p_x = ( N * ( N - 1 ) ) / 2 ; int p_y = ( M * ( M - 1 ) ) / 2 ; return p_x * p_y ; } int main ( ) { int N = 3 ; int M = 6 ; cout << count_rectangles ( N , M ) ; }