Count triangles required to form a House of Cards of height N | C ++ implementation of the above approach ; Function to find the number of triangles ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int noOfTriangles ( int n ) { return floor ( n * ( n + 2 ) * ( 2 * n + 1 ) / 8 ) ; } int main ( ) { int n = 3 ; cout << noOfTriangles ( n ) << endl ; return 0 ; }