Forming triangles using points on a square | C ++ implementation of the approach ; Function to return the count of possible triangles ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int noOfTriangles ( int n ) { int y = 4 * n ; return ( ( y * ( y - 2 ) * ( y - 1 ) ) - ( 4 * n * ( n - 2 ) * ( n - 1 ) ) ) / 6 ; } int main ( ) { int n = 1 ; cout << noOfTriangles ( n ) ; return 0 ; }