Count the total number of triangles after Nth operation | Method to return the total no . of Triangles ; For every subtriangle formed there are possibilities of generating ( curr * 3 ) + 2 ; Changing the curr value to Tri_count ; driver code
function CountTriangles ( n ) { var curr = 1 ; var Tri_count = 0 ; for ( i = 1 ; i <= n ; i ++ ) { Tri_count = ( curr * 3 ) + 2 ; curr = Tri_count ; } return Tri_count ; } var n = 10 ; document . write ( CountTriangles ( n ) ) ;