- Related Questions & Answers
- Apothem of a n-sided regular polygon in C++
- Convex Polygon in C++
- Area of largest Circle inscribed in N-sided Regular polygon in C Program?
- Area of largest Circle inscribe in N-sided Regular polygon in C Program?
- Area of a n-sided regular polygon with given Radius?
- Area of a n-sided regular polygon with given Radius in C Program?
- Area of a n-sided regular polygon with given side length in C++
- Determine the position of the third person on regular N sided polygon in C++?
- Checking for convex polygon in JavaScript
- Probability that the pieces of a broken stick form a n sided polygon in C++
- Determine the position of the third person on regular N sided polygon in C++ Program
- Find difference between sums of two diagonals in C++.
- Area of a polygon with given n ordered vertices in C++
- Find n-th Fortunate Number in C++
- Program to find the Circumcircle of any regular polygon in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have a number n, and we have to find the number of diagonals for n sided convex polygon. So if the n = 5, then diagonals count will be 5.

As this is n-sided convex polygon, from each vertex we can draw n – 3 diagonals leaving two sided adjacent vertices and itself. So for n vertices, it will be n*(n-3), but as we are considering twice, so it will be n(n – 3)/2.

#include<iostream> using namespace std; int diagonalCount(int n) { return n * (n - 3) / 2; } int main() { int n = 8; cout << n << " sided convex polygon has " << diagonalCount(n) << " diagonals"; }

8 sided convex polygon has 20 diagonals

Advertisements