Given an integer a which is the side of a regular pentagon, the task is to find and print the length of its diagonal.
Input: a = 6
Input: a = 9
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:
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live