Diagonal of a Regular Pentagon in C++?

C++Server Side ProgrammingProgramming

To find the length for the diagonal of a regular pentagon we put the value of side in (1+√5)side/2 = (1+2.24)side/2.


Let us see the following implementation to get the regular Heptagon diagonal from its side −

 Live Demo

#include <iostream>
using namespace std;
int main(){
   float side = 5;
   if (side < 0)
      return -1;
   float diagonal = (1+2.24) *(side/2);
   cout << "The diagonal of the regular pentagon = "<<diagonal<< endl;
   return 0;


The above code will produce the following output −

The diagonal of the regular pentagon = 8.1
Updated on 16-Jan-2021 10:19:00