# Largest right circular cylinder within a frustum

Given a frustum of height , top-radius & base-radius . The task is to find the volume of biggest right circular cylinder that can be inscribed within it.

**Examples:**

Input: r = 5, R = 10, h = 4Output: 314Input: r = 7, R = 11, h = 6Output: 923.16

**Approach**:

Let:

- The height of the cylinder =
**h1** - Radius of the cylinder =
**r1**

From the figure it is clear that:

- Height of the cylinder = Height of frustum
- Radius of the cylinder = Rop-radius of the frustum

So,

h1 = h r1 = r

Below is the implementation of the above approach:

## C++

`// C++ Program to find the biggest right circular cylinder ` `// that can be fit within a frustum ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the biggest right circular cylinder ` `float` `cyl(` `float` `r, ` `float` `R, ` `float` `h) ` `{ ` ` ` `// radii and height cannot be negative ` ` ` `if` `(h < 0 && r < 0 && R < 0) ` ` ` `return` `-1; ` ` ` ` ` `// radius of right circular cylinder ` ` ` `float` `r1 = r; ` ` ` `// height of right circular cylinder ` ` ` `float` `h1 = h; ` ` ` `// volume of right circular cylinder ` ` ` `float` `V = 3.14 * ` `pow` `(r1, 2) * h1; ` ` ` ` ` `return` `V; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `float` `r = 7, R = 11, h = 6; ` ` ` ` ` `cout << cyl(r, R, h) << endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to find the biggest right circular cylinder ` `// that can be fit within a frustum ` ` ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to find the biggest right circular cylinder ` ` ` `static` `float` `cyl(` `float` `r, ` `float` `R, ` `float` `h) ` `{ ` ` ` `// radii and height cannot be negative ` ` ` `if` `(h < ` `0` `&& r < ` `0` `&& R < ` `0` `) ` ` ` `return` `-` `1` `; ` ` ` ` ` `// radius of right circular cylinder ` ` ` `float` `r1 = r; ` ` ` `// height of right circular cylinder ` ` ` `float` `h1 = h; ` ` ` `// volume of right circular cylinder ` ` ` `float` `V = (` `float` `)(` `3.14` `* Math.pow(r1, ` `2` `) * h1); ` ` ` ` ` `return` `V; ` `} ` ` ` `// Driver code ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `float` `r = ` `7` `, R = ` `11` `, h = ` `6` `; ` ` ` ` ` `System.out.print( cyl(r, R, h)); ` ` ` `} ` `} ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 Program to find the biggest right circular cylinder ` `# that can be fit within a frustum ` ` ` `# Function to find the biggest right circular cylinder ` `def` `cyl(r, R, h) : ` ` ` ` ` `# radii and height cannot be negative ` ` ` `if` `(h < ` `0` `and` `r < ` `0` `and` `R < ` `0` `) : ` ` ` `return` `-` `1` ` ` ` ` `# radius of right circular cylinder ` ` ` `r1 ` `=` `r ` ` ` `# height of right circular cylinder ` ` ` `h1 ` `=` `h ` ` ` `# volume of right circular cylinder ` ` ` `V ` `=` `3.14` `*` `pow` `(r1, ` `2` `) ` `*` `h1 ` ` ` ` ` `return` `round` `(V,` `2` `) ` ` ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `r, R, h ` `=` `7` `, ` `11` `, ` `6` ` ` ` ` `print` `(cyl(r, R, h)) ` ` ` `# This code is contributed by Ryuga ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the biggest right circular cylinder ` `// that can be fit within a frustum ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to find the biggest right circular cylinder ` `static` `float` `cyl(` `float` `r, ` `float` `R, ` `float` `h) ` `{ ` ` ` `// radii and height cannot be negative ` ` ` `if` `(h < 0 && r < 0 && R < 0) ` ` ` `return` `-1; ` ` ` ` ` `// radius of right circular cylinder ` ` ` `float` `r1 = r; ` ` ` `// height of right circular cylinder ` ` ` `float` `h1 = h; ` ` ` `// volume of right circular cylinder ` ` ` `float` `V = (` `float` `)(3.14 * Math.Pow(r1, 2) * h1); ` ` ` ` ` `return` `V; ` `} ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main () { ` ` ` `float` `r = 7, R = 11, h = 6; ` ` ` ` ` `Console.WriteLine( cyl(r, R, h)); ` ` ` `} ` `} ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

## PHP

**Output:**

923.16

## Recommended Posts:

- 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 that can be inscribed within a cone
- Volume of largest right circular cylinder 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 which is in turn inscribed within a cube
- Longest rod that can be inserted within a right circular cylinder
- Volume of biggest sphere within a right circular cylinder
- Largest right circular cone that can be inscribed within a sphere
- Largest cube that can be inscribed within a right circular 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
- Program for Volume and Surface area of Frustum of Cone
- Find the perimeter of a cylinder
- Calculate Volume, Curved Surface Area and Total Surface Area Of 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.