Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone | C ++ Program to find the biggest sphere which is inscribed within a cube which in turn inscribed within a right circular cone ; Function to find the radius of the sphere ; height and radius cannot be negative ; radius of the sphere ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float sphereSide ( float h , float r ) { if ( h < 0 && r < 0 ) return -1 ; float R = ( ( h * r * sqrt ( 2 ) ) / ( h + sqrt ( 2 ) * r ) ) / 2 ; return R ; } int main ( ) { float h = 5 , r = 6 ; cout << sphereSide ( h , r ) << endl ; return 0 ; }