Dada una esfera de radio . La tarea es encontrar el volumen del cilindro circular recto más grande que se puede inscribir en él.
Ejemplos :
Input : R = 4 Output : 77.3495 Input : R = 5 Output : 151.073
Enfoque :
sea r el radio del cilindro circular recto y h su altura.
Volumen del cilindro, V = π*r 2 *h
Además, r 2 = R 2 – h 2
o, V = π*(R 2 – h 2 )*h
o, dV/dh = π*(R 2 – 3*h 2 )
Configurándolo en cero, obtenemos h = R/√3
Entonces, Vmax = 2πR 3 /3√3
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to find the biggest right circular cylinder // that can be fit within a sphere #include <bits/stdc++.h> using namespace std; // Function to find the biggest right circular cylinder float cyl(float R) { // radius cannot be negative if (R < 0) return -1; // volume of cylinder float V = (2 * 3.14 * pow(R, 3)) / (3 * sqrt(3)); return V; } // Driver code int main() { float R = 4; cout << cyl(R) << endl; return 0; }
Java
// Java Program to find the biggest // right circular cylinder that can // be fit within a sphere import java.io.*; class GFG { // Function to find the biggest // right circular cylinder static float cyl(float R) { // radius cannot be negative if (R < 0) return -1; // volume of cylinder float V = (float)((2 * 3.14 * Math.pow(R, 3)) / (3 * Math.sqrt(3))); return V; } // Driver code public static void main (String[] args) { float R = 4; System.out.print( cyl(R)); } } // This code is contributed by anuj_67..
Python 3
# Python 3 Program to find the biggest # right circular cylinder that can be # fit within a sphere import math # Function to find the biggest right # circular cylinder def cyl(R): # radius cannot be negative if (R < 0): return -1 # volume of cylinder V = ((2 * 3.14 * math.pow(R, 3)) / (3 * math.sqrt(3))); return float(V) # Driver code R = 4 print(cyl(R)) # This code is contributed # by PrinciRaj1992
C#
// C# Program to find the biggest // right circular cylinder that can // be fit within a sphere using System; class GFG { // Function to find the biggest // right circular cylinder static float cyl(float R) { // radius cannot be negative if (R < 0) return -1; // volume of cylinder float V = (float)((2 * 3.14 * Math.Pow(R, 3)) / (3 * Math.Sqrt(3))); return V; } // Driver code public static void Main () { float R = 4; Console.WriteLine( cyl(R)); } } // This code is contributed by shs
PHP
<?php // PHP Program to find the biggest right circular cylinder // that can be fit within a sphere // Function to find the biggest right circular cylinder function cyl($R) { // radius cannot be negative if ($R < 0) return -1; // volume of cylinder $V = (2 * 3.14 * pow($R, 3)) / (3 * sqrt(3)); return $V; } // Driver code $R = 4; echo cyl($R); // This code is contributed by shs ?>
Javascript
<script> // javascript Program to find the biggest // right circular cylinder that can // be fit within a sphere // Function to find the biggest // right circular cylinder function cyl(R) { // radius cannot be negative if (R < 0) return -1; // volume of cylinder var V = ((2 * 3.14 * Math.pow(R, 3)) / (3 * Math.sqrt(3))); return V; } // Driver code var R = 4; document.write( cyl(R).toFixed(4)); // This code contributed by shikhasingrajput </script>
Producción:
77.3495
Complejidad de tiempo: 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