รูปแปดเหลี่ยมคือรูปหลายเหลี่ยมที่มีแปดด้าน ในการคำนวณหาพื้นที่ของรูปแปดเหลี่ยม ให้ใช้สูตรต่อไปนี้
พื้นที่รูปแปดเหลี่ยม =((a 2 *2) / *แทน (22.5°)) =((2*a*a)(1+√2))
Code Logic พื้นที่ของรูปหลายเหลี่ยมที่มีแปดด้านคำนวณโดยใช้สูตรข้างต้น นิพจน์ใช้ฟังก์ชัน sqrt เพื่อค้นหารากที่สองของ 2 ค่าของนิพจน์จะถูกประเมินเป็นค่าทศนิยมที่ใส่ลงในตัวแปรพื้นที่ลอย
ตัวอย่าง
#include <stdio.h>
#include <math.h>
int main(){
int a = 7;
float area;
float multiplier = 6.18;
printf("Program to find area of octagon \n");
printf("The side of the octagon is %d \n", a);
area = ((2*a*a)*(1 + sqrt(2)));
printf("The area of Enneagon is %f \n", area);
return 0;
} ผลลัพธ์
Program to find area of octagon The side of the octagon is 7 The area of Enneagon is 236.592926