Diagonal of a Regular Hexagon in C++



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

Example

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;
}

Output

The above code will produce the following output −

The diagonal of the hexagon = 24
Updated on: 2021-01-16T10:16:44+05:30

128 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements