Program to calculate area of Enneagon
Last Updated :
20 Feb, 2023
Enneagon is a polygon with 9 sides and 9 internal angles. Enneagon is also known as Nonagon. A regular nonagon has an internal angle of 140 degrees each. Sum of interior angles of the nonagon is 1260 degree.
The center of the circumcircle is also taken as the center of the regular Nonagon.
The line segment drawn the perpendicular to a side of the Nonagon is called the Apothem and is represented by ‘a’.
Area ≈ 6.1818 * s * s
where s is side length.
Examples:
Input : 6
Output :Area of Regular Nonagon = 222.5448
Input : 8
Output :Area of Regular Nonagon = 395.6352
C++
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;
double Nonagon_Area( double s) {
return (6.1818 * s * s);
}
int main() {
double s = 6;
cout << "Area of Regular Nonagon = " << std::setprecision(7)
<< Nonagon_Area(s);
return 0;
}
|
Java
class Nonagon {
public static double Nonagon_Area( double s) {
return (( 6.1818 * (s * s)));
}
public static void main(String[] args) {
double s = 6 ;
System.out.print( "Area of Regular Nonagon = " + Nonagon_Area(s));
}
}
|
Python
length = 6
Nonagon_area = 6.1818 * (length * * 2 )
print ( "Area of regular Nonagon is = " , Nonagon_area)
|
C#
using System;
class Nonagon {
public static double Nonagon_Area( double s)
{
return ((6.1818 * (s * s)));
}
public static void Main()
{
double s = 6;
Console.WriteLine( "Area of Regular Nonagon = " +
Nonagon_Area(s));
}
}
|
PHP
<?php
function Nonagon_Area( $s )
{
return (6.1818 * $s * $s );
}
$s = 6;
echo "Area of Regular Nonagon = "
, Nonagon_Area( $s );
?>
|
Javascript
<script>
function Nonagon_Area(s) {
return ((6.1818 * (s * s)));
}
var s = 6;
document.write( "Area of Regular Nonagon = " + Nonagon_Area(s));
</script>
|
Output:
Area of Regular Nonagon = 222.5448
Time Complexity: O(1)
Auxiliary Space: O(1)
Please suggest if someone has a better solution which is more efficient in terms of space and time.
Share your thoughts in the comments
Please Login to comment...