Find maximum volume of a cuboid from the given perimeter and area | C ++ implementation of the above approach ; function to return maximum volume ; calculate length ; calculate volume ; return result ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; float maxVol ( float P , float A ) { float l = ( P - sqrt ( P * P - 24 * A ) ) / 12 ; float V = l * ( A / 2.0 - l * ( P / 4.0 - l ) ) ; return V ; } int main ( ) { float P = 20 , A = 16 ; cout << maxVol ( P , A ) ; return 0 ; }