Number of triangles formed from a set of points on three lines | Returns factorial of a number ; calculate c ( n , r ) ; Driver code
< ? php function factorial ( $ n ) { $ 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 ) ) ; } $ m = 3 ; $ n = 4 ; $ k = 5 ; $ totalTriangles = ncr ( $ m + $ n + $ k , 3 ) - ncr ( $ m , 3 ) - ncr ( $ n , 3 ) - ncr ( $ k , 3 ) ; echo $ totalTriangles . " STRNEWLINE " ;