Number of triangles in a plane if no more than two points are collinear Last Updated : 21 Aug, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given n points in a plane and no more than two points are collinear, the task is to count the number of triangles in a given plane. Examples: Input : n = 3 Output : 1 Input : n = 4 Output : 4 Let there are n points in a plane and no three or more points are collinear then number of triangles in the given plane is given by ^{n}\textrm{C}_{3} = \frac{n(n-1)(n-2)}{6} C++ // C++ program to find the number of // triangles in a plane if no more // then two points are collinear. #include <bits/stdc++.h> using namespace std; // Function to find number of triangles // in a plane. int countNumberOfTriangles(int n) { // Formula to find number of triangles // nC3 = n * (n - 1) * (n - 2) / 6 return n * (n - 1) * (n - 2) / 6; } // Driver code int main() { int n = 4; cout << countNumberOfTriangles(n); return 0; } C // C program to find the number of // triangles in a plane if no more // then two points are collinear. #include <stdio.h> // Function to find number of triangles // in a plane. int countNumberOfTriangles(int n) { // Formula to find number of triangles // nC3 = n * (n - 1) * (n - 2) / 6 return n * (n - 1) * (n - 2) / 6; } // Driver code int main() { int n = 4; printf("%d",countNumberOfTriangles(n)); return 0; } // This code is contributed by kothavvsaakash. Java // Java program to find the number of // triangles in a plane if no more // then two points are collinear. import java.io.*; class GFG { // Function to find number of triangles // in a plane. static int countNumberOfTriangles(int n) { // Formula to find number of triangle // nC3 = n * (n - 1) * (n - 2) / 6 return n * (n - 1) * (n - 2) / 6; } // Driver code public static void main(String[] args) { int n = 4; System.out.println( countNumberOfTriangles(n)); } } Python3 # Python3 program to find # the number of triangles # in a plane if no more # then two points are collinear. # Function to find number # of triangles in a plane. def countNumberOfTriangles(n) : # Formula to find # number of triangles # nC3 = n * (n - 1) * # (n - 2) / 6 return (n * (n - 1) * (n - 2) // 6) # Driver Code if __name__ == '__main__' : n = 4 print(countNumberOfTriangles(n)) # This code is contributed # by ajit C# // C# program to find the // number of triangles in // a plane if no more then // two points are collinear. using System; class GFG { // Function to find number // of triangles in a plane. static int countNumberOfTriangles(int n) { // Formula to find number // of triangle // nC3 = n * (n - 1) * // (n - 2) / 6 return n * (n - 1) * (n - 2) / 6; } // Driver code public static void Main() { int n = 4; Console.WriteLine( countNumberOfTriangles(n)); } } // This code is contributed by anuj_67. PHP <?php // PHP program to find the // number of triangles in a // plane if no more then // two points are collinear. // Function to find number // of triangles in a plane. function countNumberOfTriangles($n) { // Formula to find number // of triangles nC3 = n * // (n - 1) * (n - 2) / 6 return $n * ($n - 1) * ($n - 2) / 6; } // Driver code $n = 4; echo countNumberOfTriangles($n); // This code is contributed // by anuj_67. ?> JavaScript <script> // javascript program to find the number of // triangles in a plane if no more // then two points are collinear. // Function to find number of triangles // in a plane. function countNumberOfTriangles(n) { // Formula to find number of triangle // nC3 = n * (n - 1) * (n - 2) / 6 return n * (n - 1) * (n - 2) / 6; } // Driver code var n = 4; document.write(countNumberOfTriangles(n)); // This code is contributed by aashish1995 </script> Output: 4 Time complexity: O(1) Auxiliary space: O(1) Comment More infoAdvertise with us K KRV Follow Improve Article Tags : Mathematical DSA Practice Tags : Mathematical Similar Reads Mathematics | Total number of Possible Functions In this article, we are discussing how to find a number of functions from one set to another. For understanding the basics of functions, you can refer to this: Classes (Injective, surjective, Bijective) of Functions. Number of functions from one set to another: Let X and Y be two sets having m and n 5 min read Discrete Maths | Generating Functions-Introduction and Prerequisites Discrete Maths | Generating Functions-Introduction and PrerequisitesPrerequisite - Combinatorics Basics, Generalized PnC Set 1, Set 2 Definition: Generating functions are used to represent sequences efficiently by coding the terms of a sequence as coefficients of powers of a variable (say) \big x in 5 min read Mathematics | Generating Functions - Set 2 Prerequisite - Generating Functions-Introduction and Prerequisites In Set 1 we came to know basics about Generating Functions. Now we will discuss more details on Generating Functions and its applications. Exponential Generating Functions - Let h_0, h_1, h_2, ........., h_n, ...... e a sequence. The 3 min read Mathematics | Sequence, Series and Summations Sequences, series, and summations are fundamental concepts of mathematical analysis and it has practical applications in science, engineering, and finance.Table of ContentWhat is Sequence?Theorems on SequencesProperties of SequencesWhat is Series?Properties of SeriesTheorems on SeriesSummation Defin 8 min read Mathematics | Independent Sets, Covering and Matching Mathematics | Independent Sets, Covering and Matching1. Independent SetsA set of vertices I is called an independent set if no two vertices in set I are adjacent to each other in other words the set of non-adjacent vertices is called an independent set.It is also called a stable set.The parameter α0 5 min read Mathematics | Introduction to Proofs Mathematical proof is an argument we give logically to validate a mathematical statement. To validate a statement, we consider two things: A statement and Logical operators. A statement is either true or false but not both. Logical operators are AND, OR, NOT, If then, and If and only if. Coupled wit 7 min read Hasse Diagrams | Discrete Mathematics A Hasse diagram is a graphical representation of the relation of elements of a partially ordered set (poset) with an implied upward orientation. A point is drawn for each element of the partially ordered set (poset) and joined with the line segment according to the following rules: If p<q in the 10 min read Pigeonhole Principle The Pigeonhole Principle is a fundamental concept in combinatorics and mathematics that states if more items are put into fewer containers than the number of items, at least one container must contain more than one item. This seemingly simple principle has profound implications and applications in v 13 min read Combinatorics Combinatorics is the branch of Mathematics dealing with the study of finite or countable discrete structures. It includes the enumeration or counting of objects having certain properties. Counting helps us solve several types of problems such as counting the number of available IPv4 or IPv6 addresse 4 min read Mathematics | PnC and Binomial Coefficients Permutations and Combinations (PnC) are fundamental concepts in combinatorics and are essential for counting and arranging objects. Binomial coefficients are closely related and used in various mathematical formulas, including the Binomial Theorem. These concepts are widely used in engineering, comp 5 min read Like