programa para calcular area de octagono

Un octógono regular es una figura cerrada con lados de la misma longitud y ángulos internos del mismo tamaño. Tiene ocho ejes de simetría reflexiva y simetría rotacional de orden 8. El ángulo interno en cada vértice de un octágono regular es de 135°. El ángulo central es de 45°.
Propiedades : 
 

Polígono convexo, Polígono equilátero, Figura isogonal, Figura isotoxal, Cíclica.

Fórmula : 
 

Area : 2 × (side length)² × (1+sqrt(2))

Ejemplos: 
 

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 <bits/stdc++.h>
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

<?php
// PHP program to find area of octagon
 
// Utility function
function areaOctagon( $side)
{
    return (2 * (1 + sqrt(2)) *
            $side * $side);
}
 
// Driver Code
 
$side = 4;
echo("Area of Regular Octagon = ");
echo(areaOctagon($side));
 
// This code is contributed by vt_m.
?>

Javascript

<script>
 
// Javascript program to find area of octagon
 
// Utility function
function areaOctagon(side)
{
    return (2 * (1 + Math.sqrt(2)) *
                side * side);
}
 
// Driver Code
    let side = 4;
    document.write("Area of Regular Octagon = "
        + areaOctagon(side) + "<br>");
 
// This code is contributed by Mayank Tyagi
</script>

Producción : 
 

Area of Regular Octagon = 77.25

Complejidad temporal : O(1) 
Espacio auxiliar : O(1)

Publicación traducida automáticamente

Artículo escrito por nikunj_agarwal y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *