Given n > 3, find number of diagonals in n sided convex polygon.
According to Wikipedia, In geometry, a diagonal is a line segment joining two vertices of a polygon or polyhedron, when those vertices are not on the same edge. Informally, any sloping line is called diagonal.
Input : 5 Output : 5
Explanation: Five possible diagonals are : AC, AD, BD, BE, CE
Since for an n-sided convex polygon, from each vertex, we can draw n-3 diagonals leaving two adjacent vertices and itself. Following this way for n-vertices, there will be n*(n-3) diagonals but then we will be calculating each diagonal twice so total number of diagonals become n*(n-3)/2
Here is code for above formula.
5 sided convex polygon have 5 diagonals
This article is contributed by Pratik Chhajer. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if given polygon is a convex polygon or not
- Polygon with maximum sides that can be inscribed in an N-sided regular polygon
- Dynamic Convex hull | Adding Points to an Existing Convex Hull
- Program to find Area of Triangle inscribed in N-sided Regular Polygon
- Find the angle of Rotational Symmetry of an N-sided regular polygon
- Find the vertex diagonally opposite to the vertex M from an N-sided polygon
- Number of triangles formed by joining vertices of n-sided polygon with one side common
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Number of cycles formed by joining vertices of n sided polygon at the center
- Check whether two convex regular polygon have same center or not
- Check if the given point lies inside given N points of a Convex Polygon
- Probability that the pieces of a broken stick form a n sided polygon
- Side of a regular n-sided polygon circumscribed in a circle
- Area of a n-sided regular polygon with given side length
- Area of a n-sided regular polygon with given Radius
- Length of Diagonal of a n-sided regular polygon
- Apothem of a n-sided regular polygon
- Area of largest Circle inscribe in N-sided Regular polygon
- Central angle of a N sided Regular Polygon
- Check if an N-sided Polygon is possible from N given angles