Total number of triangles formed when there are H horizontal and V vertical lines | C ++ implementation of the approach ; Function to return total triangles ; Only possible triangle is the given triangle ; If only vertical lines are present ; If only horizontal lines are present ; Return total triangles ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define LLI  long long int NEW_LINE LLI totalTriangles ( LLI h , LLI v ) { if ( h == 0 && v == 0 ) return 1 ; if ( h == 0 ) return ( ( v + 1 ) * ( v + 2 ) / 2 ) ; if ( v == 0 ) return ( h + 1 ) ; LLI Total = ( h + 1 ) * ( ( v + 1 ) * ( v + 2 ) / 2 ) ; return Total ; } int main ( ) { int h = 2 , v = 2 ; cout << totalTriangles ( h , v ) ; return 0 ; }