Given an integer **a** which is the side of a regular pentagon, the task is to find and print the length of its diagonal.

**Examples:**

Input:a = 6

Output:7.32

Input:a = 9

Output:10.98

**Approach:** We know that the sum of interior angles of a polygon = **(n – 2) * 180** where, **n** is the no. of sides in the polygon.

So, sum of interior angles of pentagon = **3 * 180 = 540** and each interior angle will be **108**.

Now, we have to find **BC = 2 * x**. If we draw a perpendicular **AO** on **BC**, we will see that the perpendicular bisects **BC** in **BO** and **OC**, as triangles **AOB** and **AOC** are congruent to each other.

So, in triangle **AOB**, **sin(54) = x / a** i.e. **x = 0.61 * a**

Therefore, diagonal length will be **2 * x** i.e. **1.22 * a**.

Below is the implementation of the above approach:

## C++

`// C++ Program to find the diagonal ` `// of a regular pentagon ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the diagonal ` `// of a regular pentagon ` `float` `pentdiagonal(` `float` `a) ` `{ ` ` ` ` ` `// Side cannot be negative ` ` ` `if` `(a < 0) ` ` ` `return` `-1; ` ` ` ` ` `// Length of the diagonal ` ` ` `float` `d = 1.22 * a; ` ` ` `return` `d; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `float` `a = 6; ` ` ` `cout << pentdiagonal(a) << endl; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to find the diagonal ` `// of a regular pentagon ` `class` `GFG ` `{ ` ` ` `// Function to find the diagonal ` `// of a regular pentagon ` `static` `double` `pentdiagonal(` `double` `a) ` `{ ` ` ` ` ` `// Side cannot be negative ` ` ` `if` `(a < ` `0` `) ` ` ` `return` `-` `1` `; ` ` ` ` ` `// Length of the diagonal ` ` ` `double` `d = ` `1.22` `* a; ` ` ` `return` `d; ` `} ` ` ` `// Driver code ` `static` `public` `void` `main (String args[]) ` `{ ` ` ` `double` `a = ` `6` `; ` ` ` `System.out.println(pentdiagonal(a)); ` `} ` `} ` ` ` `// This code is contributed ` `// by Akanksha Rai ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 Program to find the diagonal ` `# of a regular pentagon ` ` ` `# Function to find the diagonal ` `# of a regular pentagon ` `def` `pentdiagonal(a) : ` ` ` ` ` `# Side cannot be negative ` ` ` `if` `(a < ` `0` `) : ` ` ` `return` `-` `1` ` ` ` ` `# Length of the diagonal ` ` ` `d ` `=` `1.22` `*` `a ` ` ` `return` `d ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `a ` `=` `6` ` ` `print` `(pentdiagonal(a)) ` ` ` `# This code is contributed by Ryuga ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the diagonal ` `// of a regular pentagon ` `using` `System; ` ` ` `public` `class` `GFG{ ` ` ` `// Function to find the diagonal ` `// of a regular pentagon ` `static` `double` `pentdiagonal(` `double` `a) ` `{ ` ` ` ` ` `// Side cannot be negative ` ` ` `if` `(a < 0) ` ` ` `return` `-1; ` ` ` ` ` `// Length of the diagonal ` ` ` `double` `d = 1.22 * a; ` ` ` `return` `d; ` `} ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main (){ ` ` ` `double` `a = 6; ` ` ` `Console.WriteLine(pentdiagonal(a)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to find the diagonal ` `// of a regular pentagon ` ` ` `// Function to find the diagonal ` `// of a regular pentagon ` `function` `pentdiagonal(` `$a` `) ` `{ ` ` ` ` ` `// Side cannot be negative ` ` ` `if` `(` `$a` `< 0) ` ` ` `return` `-1; ` ` ` ` ` `// Length of the diagonal ` ` ` `$d` `= 1.22 * ` `$a` `; ` ` ` `return` `$d` `; ` `} ` ` ` `// Driver code ` `$a` `= 6; ` `echo` `pentdiagonal(` `$a` `); ` ` ` `// This code is contributed ` `// by Sach_Code ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

7.32

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.

## Recommended Posts:

- Calculate area of pentagon with given diagonal
- Program to find the Area of Pentagon
- Filling diagonal to make the sum of every row, column and diagonal equal of 3x3 matrix
- Length of a Diagonal of a Parallelogram using the length of Sides and the other Diagonal
- Maximum sum of elements in a diagonal parallel to the main diagonal of a given Matrix
- Diagonal of a Regular Hexagon
- Diagonal of a Regular Heptagon
- Diagonal of a Regular Decagon
- Length of Diagonal of a n-sided regular polygon
- Volume of cube using its space diagonal
- Program to check diagonal matrix and scalar matrix
- Area of a square from diagonal length
- Area of hexagon with given diagonal length
- Find a Symmetric matrix of order N that contain integers from 0 to N-1 and main diagonal should contain only 0's
- Sum of non-diagonal parts of a square Matrix
- Find length of Diagonal of Hexagon
- Length of the Diagonal of the Octagon
- Program to convert the diagonal elements of the matrix to 0
- Find the area of quadrilateral when diagonal and the perpendiculars to it from opposite vertices are given
- Find the diagonal of the Cube

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.