Home >Backend Development >C++ >What is the C program for the area of ​​a hexagon given the length of its diagonal?

What is the C program for the area of ​​a hexagon given the length of its diagonal?

王林
王林forward
2023-08-30 12:25:091125browse

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.

What is the C program for the area of ​​a hexagon given the length of its diagonal?

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 -

What is the C program for the area of ​​a hexagon given the length of its diagonal?

Example

#include <iostream>
#include <cmath>
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);
}

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete