Dado un Hexágono regular de lado a , la tarea es encontrar el área del círculo inscrito en él, dado que el círculo es tangente a cada uno de los seis lados.
Ejemplos:
Input: a = 4 Output: 37.68 Input: a = 10 Output: 235.5
Enfoque :
De la figura, está claro que podemos dividir el hexágono regular en 6 triángulos equiláteros idénticos.
Tomamos un triángulo OAB , con O como el centro del hexágono o círculo, y AB como un lado del hexágono.
Sea M el punto medio de AB , OM sería la bisectriz perpendicular de AB , ángulo AOM = 30 grados
Luego, en el triángulo rectángulo OAM,
tanx = tan30 = 1/√3
Entonces, a/2r = 1/√3
Por lo tanto, r = a√3/2
Área del círculo, A =Πr²=Π3a^2/4
A continuación se muestra la implementación del enfoque :
C++
// C++ Program to find the area of the circle // which can be inscribed within the hexagon #include <bits/stdc++.h> using namespace std; // Function to find the area // of the inscribed circle float circlearea(float a) { // the side cannot be negative if (a < 0) return -1; // area of the circle float A = (3.14 * 3 * pow(a, 2)) / 4; return A; } // Driver code int main() { float a = 4; cout << circlearea(a) << endl; return 0; }
Java
//Java program to find the //area of the circle //which can be inscribed within the hexagon import java.util.*; class solution { static double circlearea(double a) { // the side cannot be negative if (a < 0) return -1; // area of the circle double A = (3.14 * 3 * Math.pow(a,2) ) / 4; return A; } public static void main(String arr[]) { double a = 4; System.out.println(circlearea(a)); } }
Python 3
# Python 3 program to find the # area of the circle # which can be inscribed within the hexagon # Function to find the area # of the inscribed circle def circlearea(a) : # the side cannot be negative if a < 0 : return -1 # area of the circle A = (3.14 * 3 * pow(a,2)) / 4 return A # Driver code if __name__ == "__main__" : a = 4 print(circlearea(a)) # This code is contributed by ANKITRAI1
C#
// C# program to find // the area of the circle // which can be inscribed // within the hexagon using System; class GFG { static double circlearea(double a) { // the side cannot be negative if (a < 0) return -1; // area of the circle double A = (3.14 * 3 * Math.Pow(a, 2)) / 4; return A; } // Driver Code public static void Main() { double a = 4; Console.WriteLine(circlearea(a)); } } // This code is contributed // by inder_verma
PHP
<?php // PHP Program to find the area of // the circle which can be inscribed // within the hexagon // Function to find the area // of the inscribed circle function circlearea($a) { // the side cannot be negative if ($a < 0) return -1; // area of the circle $A = (3.14 * 3 * pow($a, 2)) / 4; return $A; } // Driver code $a = 4; echo circlearea($a) . "\n"; // This code is contributed // by Akanksha Rai(Abby_akku)
Javascript
<script> // javascript program to find the //area of the circle //which can be inscribed within the hexagon function circlearea(a) { // the side cannot be negative if (a < 0) return -1; // area of the circle var A = (3.14 * 3 * Math.pow(a, 2)) / 4; return A; } var a = 4; document.write(circlearea(a)); // This code is contributed by 29AjayKumar </script>
37.68
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA