Aquí se da un triángulo equilátero con lado de longitud a , que inscribe un círculo, que a su vez inscribe un cuadrado. La tarea es encontrar el área de este cuadrado.
Ejemplos:
Input: a = 6 Output: 1 Input: a = 10 Output: 0.527046
Enfoque :
sea r el radio del círculo,
por lo tanto es el interior del radio del triángulo equilátero, entonces r = a /(2 * √3)
diagonal del cuadrado, d = diámetro del círculo = 2 * r = a/ √3
Entonces, el área de cuadrado, A = 0.5 * d * d
por lo tanto A = (1/2) * (a^2) / (3) = (a^2/6)
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to find the area of the square // inscribed within the circle which in turn // is inscribed in an equilateral triangle #include <bits/stdc++.h> using namespace std; // Function to find the area of the square float area(float a) { // a cannot be negative if (a < 0) return -1; // area of the square float area = sqrt(a) / 6; return area; } // Driver code int main() { float a = 10; cout << area(a) << endl; return 0; }
Java
// Java Program to find the area of the square // inscribed within the circle which in turn // is inscribed in an equilateral triangle import java.io.*; class GFG { // Function to find the area of the square static float area(float a) { // a cannot be negative if (a < 0) return -1; // area of the square float area = (float)Math.sqrt(a) / 6; return area; } // Driver code public static void main (String[] args) { float a = 10; System.out.println( area(a)); // This code is contributed // by inder_verma.. } }
Python 3
# Python3 Program to find the area # of the square inscribed within # the circle which in turn is # inscribed in an equilateral triangle # import everything from math lib. from math import * # Function to find the area # of the square def area(a): # a cannot be negative if a < 0 : return -1 # area of the square area = sqrt(a) / 6 return area # Driver code if __name__ == "__main__" : a = 10 print(round(area(a), 6)) # This code is contributed by ANKITRAI1
C#
// C# Program to find the area // of the square inscribed within // the circle which in turn is // inscribed in an equilateral triangle using System; class GFG { // Function to find the area // of the square static float area(float a) { // a cannot be negative if (a < 0) return -1; // area of the square float area = (float)Math.Sqrt(a) / 6; return area; } // Driver code public static void Main () { float a = 10; Console.WriteLine(area(a)); } } // This code is contributed // by inder_verma
PHP
<?php // PHP Program to find the area // of the square inscribed within // the circle which in turn is // inscribed in an equilateral triangle // Function to find the // area of the square function area($a) { // a cannot be negative if ($a < 0) return -1; // area of the square $area = sqrt($a) / 6; return $area; } // Driver code $a = 10; echo area($a); // This code is contributed // by inder_verma ?>
Javascript
<script> // javascript Program to find the area of the square // inscribed within the circle which in turn // is inscribed in an equilateral triangle // Function to find the area of the square function area(a) { // a cannot be negative if (a < 0) return -1; // area of the square var area = Math.sqrt(a) / 6; return area; } // Driver code var a = 10; document.write( area(a).toFixed(6)); // This code contributed by shikhasingrajput </script>
Producción:
0.527046
Complejidad de tiempo : O(logn)
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