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 = 6Output: r = 4.24264, h = 6Input: a = 10Output: 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/√2****h = 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; ` `} ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

r = 4.24264, h = 6

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Largest right circular cylinder that can be inscribed within a cone which is in turn inscribed within a cube
- Largest right circular cone that can be inscribed within a sphere which is inscribed within a cube
- Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone
- Largest cube that can be inscribed within a right circular cone
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
- Largest right circular cone that can be inscribed within a sphere
- Largest right circular cylinder that can be inscribed within a cone
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Largest cube that can be inscribed within the sphere
- Largest cube that can be inscribed within a right circular cylinder
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Largest sphere that can be inscribed inside a cube
- Largest sphere that can be inscribed in a right circular cylinder inscribed in a frustum
- Biggest Reuleaux Triangle within a Square which is inscribed within a Circle
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Area of largest triangle that can be inscribed within a rectangle
- Largest Square that can be inscribed within a hexagon
- Largest hexagon that can be inscribed within a square

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.