Longest rod that can be inserted within a right circular cylinder | C ++ Program to find the longest rod that can be fit within a right circular cylinder ; Function to find the side of the cube ; height and radius cannot be negative ; length of rod ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float rod ( float h , float r ) { if ( h < 0 && r < 0 ) return -1 ; float l = sqrt ( pow ( h , 2 ) + 4 * pow ( r , 2 ) ) ; return l ; } int main ( ) { float h = 4 , r = 1.5 ; cout << rod ( h , r ) << endl ; return 0 ; }