Dado que aquí hay un decágono regular, inscrito dentro de un círculo de radio r , la tarea es encontrar el área del decágono.
Ejemplos:
Input: r = 5 Output: 160.144 Input: r = 8 Output: 409.969
Enfoque :
Sabemos, lado del decágono dentro del círculo, a = r√(2-2cos36) ( Consulte aquí )
Entonces, área del decágono,
A = 5*a^2*(√5+2√5)/2 = 5 *(r√(2-2cos36))^2*(√5+2√5)/2=(5*r^2 *(3-√5)*(√5+2√5))/4
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to find the area of the decagon // inscribed within a circle #include <bits/stdc++.h> using namespace std; // Function to find the area of the decagon float area(float r) { // radius cannot be negative if (r < 0) return -1; // area of the decagon float area = (5 * pow(r, 2) * (3 - sqrt(5)) * (sqrt(5) + (2 * sqrt(5)))) / 4; return area; } // Driver code int main() { float r = 8; cout << area(r) << endl; return 0; }
Python3
# Python3 Program to find the area of # the decagon inscribed within a circle from math import sqrt,pow # Function to find the # area of the decagon def area(r): # radius cannot be negative if r < 0: return -1 # area of the decagon area = (5 * pow(r, 2) * (3 - sqrt(5)) * (sqrt(5) + (2 * sqrt(5))))/ 4 return area # Driver code if __name__ == '__main__': r = 8 print(area(r)) # This code is contributed # by Surendra_Gangwar
C#
// C# Program to find the area of the // decagon inscribed within a circle using System; class GFG { // Function to find the area // of the decagon static double area(double r) { // radius cannot be negative if (r < 0) return -1; // area of the decagon double area = (5 * Math.Pow(r, 2) * (3 - Math.Sqrt(5)) * (Math.Sqrt(5) + ((2 * Math.Sqrt(5))))/ 4); return area; } // Driver code static public void Main () { double r = 8; Console.WriteLine (area(r)); } } // This code is contributed by akt_mit
PHP
<?php // PHP Program to find the area // of the decagon inscribed within // a circle // Function to find the area // of the decagon function area($r) { // radius cannot be negative if ($r < 0) return -1; // area of the decagon $area = (5 * pow($r, 2) * (3 - sqrt(5)) * (sqrt(5) + (2 * sqrt(5)))) / 4; return $area; } // Driver code $r = 8; echo area($r) . "\n"; // This code is contributed // by Akanksha Rai(Abby_akku) ?>
Javascript
<script> // javascript Program to find the area of the decagon // inscribed within a circle // Function to find the area of the decagon function area( r) { // radius cannot be negative if (r < 0) return -1; // area of the decagon var area = (5 * Math.pow(r, 2) * (3 - Math.sqrt(5)) * (Math.sqrt(5) + ((2 * Math.sqrt(5))))/ 4); return area; } // Driver code var r = 8; document.write(area(r).toFixed(3)); // This code is contributed by 29AjayKumar </script>
Producción:
409.969
Complejidad temporal: O(1), ya que no hay bucle ni recursividad.
Espacio Auxiliar: O(1), ya que no se ha ocupado ningún espacio extra.
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA