正八边形是具有相同长度的边和相同尺寸的内角的闭合图形。它具有8条反射对称性和8次旋转对称性的线。正八边形的每个顶点的内角为135°。中心角为45°。
特性 :
Convex polygon, Equilateral polygon, Isogonal figure, Isotoxal figure, Cyclic.
公式 :
Area : 2 × (side length)² × (1+sqrt(2))
例子 :
Input : side = 3
Output : Area of Regular Octagon = 43.4558
Input : side = 4
Output : Area of Regular Octagon = 77.2548
C++
// CPP program to find area of octagon
#include
using namespace std;
// Utility function
double areaOctagon(double side)
{
return (float)(2 * (1 + sqrt(2)) *
side * side);
}
// Driver Code
int main()
{
double side = 4;
cout << "Area of Regular Octagon = "
<< areaOctagon(side) << endl;
return 0;
}
Java
// Java Program to find
// area of Octagon.
import java.io.*;
class GFG
{
// utility function
static double areaOctagon(double side)
{
return (float)(2 * (1 + Math.sqrt(2))
* side * side);
}
// driver code
public static void main(String arg[])
{
double side = 4;
System.out.print("Area of Regular Octagon = "
+ areaOctagon(side));
}
}
// This code is contributed by Anant Agarwal.
Python3
# Python3 program to
# find area of octagon
import math
# Utility function
def areaOctagon(side):
return (2 * (1 + (math.sqrt(2))) * side * side)
# Driver function
side = 4
print("Area of Regular Octagon =",
round(areaOctagon(side), 4))
# This code is contributed
# by Azkia Anam.
C#
// C# Program to find
// area of Octagon.
using System;
class GFG
{
// utility function
static double areaOctagon(double side)
{
return (float)(2 * (1 + Math.Sqrt(2))
* side * side);
}
// Driver code
public static void Main()
{
double side = 4;
Console.WriteLine("Area of Regular Octagon = "
+ areaOctagon(side));
}
}
// This code is contributed by vt_m.
PHP
Javascript
输出 :
Area of Regular Octagon = 77.2548