Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
C Program for area of hexagon with given diagonal length?
Here we will see how to get the area of one hexagon using diagonal length. The diagonal length of the hexagon is d.
The interior angles of a regular hexagon are 120° each. The sum of all interior angles are 720°. If the diagonal is d, then the area formula is −
Syntax
Area = (3 × ?3 × d²) / 8
Example
The following program calculates the area of a regular hexagon using its diagonal length −
#include <stdio.h>
#include <math.h>
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 diagonal = 10;
float result = area(diagonal);
if (result == -1) {
printf("Invalid diagonal length
");
} else {
printf("Diagonal length: %.2f
", diagonal);
printf("Area of hexagon: %.4f
", result);
}
return 0;
}
Output
Diagonal length: 10.00 Area of hexagon: 64.9519
Key Points
- The formula uses the diagonal length (distance between opposite vertices) of a regular hexagon.
- The constant factor (3?3)/8 ? 0.6495 comes from hexagonal geometry.
- Input validation ensures the diagonal length is positive.
Conclusion
The area of a regular hexagon can be calculated using its diagonal length with the formula (3?3 × d²)/8. This approach is useful when only the diagonal measurement is available.
Advertisements
