Dado un semicírculo de radio R , la tarea es encontrar el área del círculo más grande que se puede inscribir en el semicírculo.
Ejemplos:
Input: R = 2 Output: 3.14 Input: R = 8 Output: 50.24
Aproximación : Sea R el radio del semicírculo
- Para el círculo más grande que se puede inscribir en este semicírculo, el diámetro del círculo debe ser igual al radio del semicírculo.
- Entonces, si el radio del semicírculo es R , entonces el diámetro del círculo inscrito más grande será R .
- Por lo tanto, el radio del círculo inscrito debe ser R/2
- Por lo tanto, el área del círculo más grande será
Area of circle = pi*Radius2 = pi*(R/2)2 since the radius of largest circle is R/2 where R is the radius of the semicircle
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to find the biggest circle // which can be inscribed within the semicircle #include <bits/stdc++.h> using namespace std; // Function to find the area // of the circle float circlearea(float R) { // Radius cannot be negative if (R < 0) return -1; // Area of the largest circle float a = 3.14 * R * R / 4; return a; } // Driver code int main() { float R = 2; cout << circlearea(R) << endl; return 0; }
Java
// Java Program to find the biggest circle // which can be inscribed within the semicircle class GFG { // Function to find the area // of the circle static float circlearea(float R) { // Radius cannot be negative if (R < 0) return -1; // Area of the largest circle float a = (float)((3.14 * R * R) / 4); return a; } // Driver code public static void main (String[] args) { float R = 2; System.out.println(circlearea(R)); } } // This code is contributed by AnkitRai01
Python3
# Python3 Program to find the biggest circle # which can be inscribed within the semicircle # Function to find the area # of the circle def circlearea(R) : # Radius cannot be negative if (R < 0) : return -1; # Area of the largest circle a = (3.14 * R * R) / 4; return a; # Driver code if __name__ == "__main__" : R = 2; print(circlearea(R)) ; # This code is contributed by AnkitRai01
C#
// C# Program to find the biggest circle // which can be inscribed within the semicircle using System; class GFG { // Function to find the area // of the circle static float circlearea(float R) { // Radius cannot be negative if (R < 0) return -1; // Area of the largest circle float a = (float)((3.14 * R * R) / 4); return a; } // Driver code public static void Main (string[] args) { float R = 2; Console.WriteLine(circlearea(R)); } } // This code is contributed by AnkitRai01
Javascript
<script> // Javascript Program to find the biggest circle // which can be inscribed within the semicircle // Function to find the area // of the circle function circlearea(R) { // Radius cannot be negative if (R < 0) return -1; // Area of the largest circle var a = 3.14 * R * R / 4; return a; } // Driver code var R = 2; document.write(circlearea(R)); // This code is contributed by rutvik_56. </script>
Producción:
3.14
Complejidad de tiempo : O(1)
Espacio Auxiliar: O(1)