Dado un entero d que es la longitud de la diagonal de un pentágono , la tarea es encontrar el área de ese pentágono.
Ejemplos:
Entrada: d = 5
Salida: 16,4291
Entrada: d = 10
Salida: 65,7164
Enfoque: Pentágono es un polígono regular que tiene cinco lados iguales y todos los ángulos iguales. Los ángulos interiores del pentágono son de 108 grados cada uno y la suma de todos los ángulos de un pentágono es de 540 grados. Si d es la diagonal del pentágono, entonces su área está dada por:
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to find the area of // Pentagon with given diagonal #include <bits/stdc++.h> using namespace std; // Function to return the area of the // pentagon with diagonal d float pentagonArea(float d) { float area; // Formula to find area area = (d * d * (-5 + sqrt(45)) * sqrt(sqrt(20) + 5)) / 8; return area; } // Driver code int main() { float d = 5; cout << pentagonArea(d); return 0; }
Java
// Java program to find the area of // Pentagon with given diagonal import java.text.*; class GFG{ // Function to return the area of the // pentagon with diagonal d static double pentagonArea(double d) { double area; // Formula to find area area = (d * d * (-5 + Math.sqrt(45)) * Math.sqrt(Math.sqrt(20) + 5)) / 8; return area; } // Driver code public static void main(String[] args) { double d = 5; DecimalFormat dec = new DecimalFormat("#0.0000"); System.out.println(dec.format(pentagonArea(d))); } } // This code is contributed by mits
Python3
# Python3 program to find the area of # Pentagon with given diagonal # from math lib import sqrt() method from math import sqrt # Function to return the area of the # pentagon with diagonal d def pentagonArea(d) : # Formula to find area area = (d * d * (-5 + sqrt(45)) * sqrt(sqrt(20) + 5)) / 8 return round(area , 4) # Driver code if __name__ == "__main__" : d = 5 print(pentagonArea(d)) # This code is contributed by Ryuga
C#
// C# program to find the area of // Pentagon with given diagonal using System; class GFG{ // Function to return the area of the // pentagon with diagonal d static double pentagonArea(double d) { double area; // Formula to find area area = (d * d * (-5 + Math.Sqrt(45)) * Math.Sqrt(Math.Sqrt(20) + 5)) / 8; return area; } // Driver code public static void Main() { double d = 5; Console.WriteLine("{0:F4}",pentagonArea(d)); } } // This code is contributed by mits
PHP
<?php // PHP program to find the area of // Pentagon with given diagonal // Function to return the area of the // pentagon with diagonal d Function pentagonArea($d) { $area; // Formula to find area $area= ($d * $d * (-5 +sqrt(45)) * sqrt(sqrt(20) + 5)) / 8; return $area; } // Driver code { $d = 5; echo(pentagonArea($d)); return 0; } //This code is contributed by Mukul singh.
Javascript
<script> // javascript program to find the area of // Pentagon with given diagonal // Function to return the area of the // pentagon with diagonal d function pentagonArea( d) { let area; // Formula to find area area = (d * d * (-5 + Math.sqrt(45)) * Math.sqrt(Math.sqrt(20) + 5)) / 8; return area; } // Driver code let d = 5; document.write(pentagonArea(d).toFixed(4)); // This code is contributed by gauravrajput1 </script>
Producción:
16.4291
Complejidad de tiempo: O(1)
Espacio Auxiliar: O(1)