Program to calculate Area Of Octagon

An octagon is a polygon with eight sides. To calculate the area of a regular octagon, we use a specific mathematical formula based on the side length.

Syntax

Area = 2 * (1 + ?2) * side²

Where side is the length of one side of the regular octagon.

Formula Explanation

The area of a regular octagon can be calculated using the formula −

Area = 2 * (1 + ?2) * a²

Where:

  • a is the side length of the octagon
  • ?2 is approximately 1.414
  • The coefficient 2 * (1 + ?2) is approximately 4.828

Example

This program calculates the area of an octagon with a given side length −

#include <stdio.h>
#include <math.h>

int main() {
    float side = 7.0;
    float area;
    
    printf("Program to find area of octagon<br>");
    printf("The side of the octagon is %.1f<br>", side);
    
    area = 2 * (1 + sqrt(2)) * side * side;
    
    printf("The area of octagon is %.2f<br>", area);
    
    return 0;
}
Program to find area of octagon
The side of the octagon is 7.0
The area of octagon is 236.59

Key Points

  • The formula works only for regular octagons where all sides are equal
  • The sqrt() function from math.h is used to calculate the square root of 2
  • Use float or double data types for accurate area calculations

Conclusion

The area of a regular octagon is calculated using the formula 2 * (1 + ?2) * side². This formula provides an accurate measurement for any regular octagon when the side length is known.

Updated on: 2026-03-15T10:47:21+05:30

933 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements