Count of Equilateral Triangles of unit length possible from a given Hexagon | C ++ program to implement the above approach ; Function to calculate the the number of Triangles possible ; Driver Code ; Regular Hexagon ; Irregular Hexagon
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculateTriangles ( int sides [ ] ) { double count = pow ( sides [ 0 ] + sides [ 1 ] + sides [ 2 ] , 2 ) ; count -= pow ( sides [ 0 ] , 2 ) ; count -= pow ( sides [ 2 ] , 2 ) ; count -= pow ( sides [ 4 ] , 2 ) ; return ( int ) ( count ) ; } int main ( ) { int sides [ ] = { 1 , 1 , 1 , 1 , 1 , 1 } ; cout << ( calculateTriangles ( sides ) ) << endl ; int sides1 [ ] = { 2 , 2 , 1 , 3 , 1 , 2 } ; cout << ( calculateTriangles ( sides1 ) ) << endl ; return 0 ; }