计算八边形面积的程序
八边形是具有八个边的多边形。要计算八边形的面积,请使用以下公式,
八边形的面积=((a2*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