Diagonal of a Regular Hexagon in C++ Program

C++Server Side ProgrammingProgramming

In this tutorial, we are going to learn how to find the diagonal of a regular hexagon.

We have to find the length of the diagonal of the regular hexagon using the given side. The length of the diagonal of a regular hexagon is 1.73 * s where s is the side of the hexagon.


Let's see the code.

 Live Demo

#include <bits/stdc++.h>
using namespace std;
float hexagonDiagonal(float s) {
   if (s < 0) {
      return -1;
   return 1.73 * s;
int main() {
   float s = 7;
   cout << hexagonDiagonal(s) << endl;
   return 0;


If you run the above code, then you will get the following result.



If you have any queries in the tutorial, mention them in the comment section.

Updated on 27-Jan-2021 12:32:06