แปดเหลี่ยมเป็นรูปหลายเหลี่ยม 8 ด้าน สูตรคำนวณพื้นที่:
Area = ((a²×2) / tan(22.5°)) = ((2×a×a)(1+√2))
โค้ดใช้ sqrt() หารากที่ 2 ค่าสมการคำนวณเป็น float
ตัวอย่าง
#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