Here we will learn how to use the diagonal length to get the area of a hexagon. The diagonal length of a hexagon is d.
The interior angles of a regular hexagon are each 120°. The sum of all interior angles is 720°. If the diagonal is d, the area is -
#include#include using namespace std; float area(float d) { if (d < 0) //if d is negative it is invalid return -1; float area = (3 * sqrt(3) * d*d)/8.0; return area; } int main() { float r = 10; cout << "Area : " << area(r); }
Area : 64.9519
The above is the detailed content of What is the C program for the area of a hexagon given the length of its diagonal?. For more information, please follow other related articles on the PHP Chinese website!