Given a sphere of radius . The task is to find volume of the biggest right circular cylinder that can be inscribed within it.

**Examples**:

Input: R = 4Output: 77.3495Input: R = 5Output: 151.073

**Approach**:

let **r** be the radius of the right circular cylinder, and **h** be it’s height.

Volume of the cylinder, **V = π*r ^{2}*h**

Also, **r ^{2} = R^{2} – h^{2}**

or,

**V = π*(R**

^{2}– h^{2})*hor,

**dV/dh = π*(R**

^{2}– 3*h^{2})Setting it to zero, we get **h = R/√3**

So, **Vmax = 2πR ^{3}/3√3**

Below is the implementation of the above approach:

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

*chevron_right*

*filter_none*

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

*chevron_right*

*filter_none*

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

*chevron_right*

*filter_none*

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

*chevron_right*

*filter_none*

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

*chevron_right*

*filter_none*

**Output:**

77.3495

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:

- Volume of biggest sphere within a right circular cylinder
- Largest sphere that can be inscribed in a right circular cylinder inscribed in a frustum
- Largest right circular cylinder within a cube
- Largest right circular cylinder within a frustum
- Largest right circular cone that can be inscribed within a sphere
- Largest cube that can be inscribed within a right circular cylinder
- Largest right circular cylinder that can be inscribed within a cone
- Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone
- Largest right circular cone that can be inscribed within a sphere which is inscribed within a cube
- Largest right circular cylinder that can be inscribed within a cone which is in turn inscribed within a cube
- Calculate Volume and Surface area Of Sphere
- Minimum volume of cone that can be circumscribed about a sphere of radius R
- Longest rod that can be inserted within a right circular cylinder
- Percentage increase in volume of the sphere if radius is increased by a given percentage
- Largest cube that can be inscribed within the sphere
- Largest sphere that can be inscribed inside a cube
- Calculate Volume, Curved Surface Area and Total Surface Area Of Cylinder
- Largest cube that can be inscribed within a right circular cone
- LS3/NS3 sphere generation algorithm and its implementation
- Find the perimeter of a cylinder

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.