Number of triangles formed from a set of points on three lines | Returns factorial of a number ; calculate c ( n , r ) ; Driver code
function factorial ( n ) { var fact = 1 ; for ( i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } function ncr ( n , r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } var m = 3 , n = 4 , k = 5 ; var totalTriangles = ncr ( m + n + k , 3 ) - ncr ( m , 3 ) - ncr ( n , 3 ) - ncr ( k , 3 ) ; document . write ( totalTriangles ) ;