Largest right circular cylinder that can be inscribed within a cone | Function to find the biggest right circular cylinder ; radius and height cannot be negative ; radius of right circular cylinder ; height of right circular cylinder ; volume of right circular cylinder ; Driver code
< ? php function cyl ( $ r , $ h ) { if ( $ r < 0 && $ h < 0 ) return -1 ; $ R = ( int ) ( 2 * $ r ) / 3 ; $ H = ( int ) ( 2 * $ h ) / 3 ; $ V = 3.14 * pow ( $ R , 2 ) * $ H ; return $ V ; } $ r = 4 ; $ h = 8 ; echo cyl ( $ r , $ h ) ; ? >