text: Length of longest rod that can fit into a cuboid | C ++ program to find the longest rod that can fit in a cuboid ; Function to find the length ; temporary variable to hold the intermediate result ; length of longest rod is calculated using square root function ; Driver code ; calling longestRodInCuboid ( ) function to get the length of longest rod
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; double longestRodInCuboid ( int length , int breadth , int height ) { double result ; int temp ; temp = length * length + breadth * breadth + height * height ; result = sqrt ( temp ) ; return result ; } int main ( ) { int length = 12 , breadth = 9 , height = 8 ; cout << longestRodInCuboid ( length , breadth , height ) ; return 0 ; }