# 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.

## Example

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

## Output

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

12.11

## Conclusion

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

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