Find Maximum Volume of a Cuboid from Given Perimeter and Area in C++



Suppose we have the area A and a perimeter P, now we have to find what will be the maximum volume that can be made in form of cuboid from given perimeter and surface area. So when the P is 24 and A is 24, then the output will be 8.

As we know for given perimeter of cuboid P = 4(length + breadth + Depth), for area, it will be A = 2(length* breadth + breadth*Depth + length *Depth), and the volume is V = (length* breadth*Depth)

Example

 Live Demo

#include<iostream>
#include<cmath>
using namespace std;
float maxVolumeCuboid(float Peri, float Area) {
   float length = (Peri - sqrt(Peri * Peri - 24 * Area)) / 12;
   float Vol = length * (Area / 2.0 - length * (Peri / 4.0 - length));
   return Vol;
}
int main() {
   float P = 20, A = 16;
   cout << "Maximum volume of the cuboid will be: " << maxVolumeCuboid(P, A);
}

Output

Maximum volume of the cuboid will be: 4.14815
Updated on: 2019-12-18T11:14:07+05:30

429 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements