Home > Backend Development > C++ > body text

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

王林
Release: 2023-08-30 12:25:09
forward
1038 people have browsed it

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);
}
Copy after login

Output

Area : 64.9519
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!