Largest cone that can be inscribed within a cube Last Updated : 27 Aug, 2022 Comments Improve Suggest changes Like Article Like Report Given here is a cube of side length a. We have to find the height and the radius of the biggest right circular cone that can be inscribed within it.Examples: Input : a = 6 Output : r = 4.24264, h = 6 Input : a = 10 Output : r = 7.07107, h = 10 Approach: Let height of the cone = h. and, radius of the cone = r.From the diagram, we can clearly understand that, r = a/?2h = a Below is the implementation of the above approach: C++ // C++ Program to find the biggest cone // inscribed within a cube #include <bits/stdc++.h> using namespace std; // Function to find the radius of the cone float coneRadius(float a) { // side cannot be negative if (a < 0) return -1; // radius of the cone float r = a / sqrt(2); return r; } // Function to find the height of the cone float coneHeight(float a) { // side cannot be negative if (a < 0) return -1; // height of the cone float h = a; return h; } // Driver code int main() { float a = 6; cout << "r = " << coneRadius(a) << ", " << "h = " << coneHeight(a) << endl; return 0; } Java // Java Program to find the biggest // cone inscribed within a cube import java.util.*; import java.lang.*; class GFG { // Function to find the radius // of the cone static float coneRadius(float a) { // side cannot be negative if (a < 0) return -1; // radius of the cone float r = (float)(a / Math.sqrt(2)); return r; } // Function to find the height // of the cone static float coneHeight(float a) { // side cannot be negative if (a < 0) return -1; // height of the cone float h = a; return h; } // Driver code public static void main(String args[]) { float a = 6; System.out.println("r = " + coneRadius(a) + ", " + "h = " + coneHeight(a)); } } // This code is contributed // by Akanksha Rai Python 3 # Python 3 Program to find the biggest # cone inscribed within a cube import math # Function to find the radius # of the cone def coneRadius(a): # side cannot be negative if (a < 0): return -1 # radius of the cone r = a / math.sqrt(2) return r # Function to find the height of the cone def coneHeight(a): # side cannot be negative if (a < 0): return -1 # height of the cone h = a return h # Driver code if __name__ == "__main__": a = 6 print("r = ", coneRadius(a) , "h = ", coneHeight(a)) # This code is contributed by ChitraNayal C# // C# Program to find the biggest // cone inscribed within a cube using System; class GFG { // Function to find the radius // of the cone static float coneRadius(float a) { // side cannot be negative if (a < 0) return -1; // radius of the cone float r = (float)(a / Math.Sqrt(2)); return r; } // Function to find the height // of the cone static float coneHeight(float a) { // side cannot be negative if (a < 0) return -1; // height of the cone float h = a; return h; } // Driver code public static void Main() { float a = 6; Console.WriteLine("r = " + coneRadius(a) + ", " + "h = " + coneHeight(a)); } } // This code is contributed // by Akanksha Rai PHP <?php // PHP Program to find the biggest // cone inscribed within a cube // Function to find the radius // of the cone function coneRadius($a) { // side cannot be negative if ($a < 0) return -1; // radius of the cone $r = $a / sqrt(2); return $r; } // Function to find the height // of the cone function coneHeight($a) { // side cannot be negative if ($a < 0) return -1; // height of the cone $h = $a; return $h; } // Driver code $a = 6; echo ("r = "); echo coneRadius($a); echo (", "); echo ("h = "); echo (coneHeight($a)); // This code is contributed // by Shivi_Aggarwal ?> JavaScript <script> // javascript Program to find the biggest // cone inscribed within a cube // Function to find the radius // of the cone function coneRadius(a) { // side cannot be negative if (a < 0) return -1; // radius of the cone var r = (a / Math.sqrt(2)); return r; } // Function to find the height // of the cone function coneHeight(a) { // side cannot be negative if (a < 0) return -1; // height of the cone var h = a; return h; } // Driver code var a = 6; document.write("r = " + coneRadius(a).toFixed(5) + ", " + "h = " + coneHeight(a)); // This code is contributed by 29AjayKumar </script> Output: r = 4.24264, h = 6 Time Complexity: O(1) Auxiliary Space: O(1), since no extra space has been taken. Comment More infoAdvertise with us Next Article Largest cube that can be inscribed within a right circular cylinder I IshwarGupta Follow Improve Article Tags : Mathematical Geometric DSA Practice Tags : GeometricMathematical Similar Reads Largest cube that can be inscribed within a right circular cone Given a right circular cone of radius r and perpendicular height h. We have to find the side length of the biggest cube that can be inscribed within it.Examples: Input : h = 5, r = 6 Output : 3.14613 Input : h = 8, r = 12 Output : 5.43698 Approach: Let, side of the cube = a.From the diagram, we can 4 min read Largest cube that can be inscribed within the sphere Given here is a sphere of radius r, the task is to find the side of the largest cube that can fit inside in it.Examples: Input: r = 8 Output: 9.2376 Input: r = 5 Output: 5.7735 Approach: Side of the cube = a Radius of the sphere = r From the diagonal, it is clear that, diagonal of the cube = diamete 3 min read Largest cube that can be inscribed within a right circular cylinder Given here is a right circular cylinder of height h and radius r. The task is to find the volume of biggest cube that can be inscribed within it.Examples: Input: h = 3, r = 2 Output: volume = 27 Input: h = 5, r = 4 Output: volume = 125 Approach: From the figure, it can be clearly understand that sid 4 min read Largest right circular cone that can be inscribed within a sphere Given sphere of radius r . The task is to find the radius of base and height of the largest right circular cone that can be inscribed within it.Examples: Input : R = 10 Output : r = 9.42809, h = 13.3333 Input : R = 25 Output : r = 23.5702, h = 33.3333 Approach:Let the radius of the cone = r height o 6 min read Largest sphere that can be inscribed inside a cube Given here is a cube of side length a, the task is to find the biggest sphere that can be inscribed within it.Examples: Input: a = 4 Output: 2 Input: a = 5 Output: 2.5 Approach: From the 2d diagram it is clear that, 2r = a, where, a = side of the cube r = radius of the sphere so r = a/2. Below is th 3 min read Largest triangle that can be inscribed in a semicircle Given a semicircle with radius r, we have to find the largest triangle that can be inscribed in the semicircle, with base lying on the diameter.Examples: Input: r = 5 Output: 25 Input: r = 8 Output: 64 Approach: From the figure, we can clearly understand the biggest triangle that can be inscribed in 3 min read Like