Home > Backend Development > C++ > body text

In a C program, what is the area of ​​a hexagon given the length of its diagonal?

WBOY
Release: 2023-08-27 10:25:06
forward
1069 people have browsed it

In a C program, what is the area of ​​a hexagon given the length of its diagonal?

A hexagon is a closed figure of a hexagon, and a regular hexagon is a hexagon with six equal sides and equal angles. To find the area of ​​a hexagon, we are given only the length of its diagonal, which is d.

Each interior angle of a hexagon is 120 degrees, and the sum of all angles of a hexagon is 720 degrees.

The formula to find the area of ​​a hexagon with side length a,

Area = (3a<sup>2</sup> &radic;3) / 2.
Copy after login

Since all sides are the same size and the angle is 120 degrees,

d = 2a or a = d/2
Copy after login

By changing the value of a Denoted as d, we get the area with respect to d. The Chinese translation of

2 &radic;3 ) / 8
Copy after login

Example

is:

Example

#include <stdio.h>
#include<math.h>
int main() {
   float d = 10;
   float area = (3 * sqrt(3) * pow(d, 2)) / 8;
   printf("Area of hexagon = %f",area);
   return 0;
}
Copy after login

Output

Area of hexagon = 64.951904
Copy after login

The above is the detailed content of In a C program, what is the area of ​​a hexagon given the length of its diagonal?. For more information, please follow other related articles on the PHP Chinese website!

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!