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.

d Regular Hexagon with Diagonal d 120°

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.

Updated on: 2026-03-15T11:46:12+05:30

478 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements