Diagonal of a Regular Hexagon in C++?

C++Server Side ProgrammingProgramming

The regular hexagons are comprised of six equilateral triangles so the diagonal of a regular hexagon would be 2*side.


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 = 12;
   if (side < 0)
      return -1;
   float diagonal = 2*side;
   cout << "The diagonal of the regular hexagon = "<<diagonal<< endl;
   return 0;


The above code will produce the following output −

The diagonal of the hexagon = 24
Updated on 16-Jan-2021 10:16:44