在 C++ 中查找给定周长和面积的最大长方体体积


假设我们有面积 A 和周长 P,现在我们必须找到最大体积,该体积可以以长方体的形式由给定的周长和表面积制成。因此,当 P 为 24,且 A 为 24 时,其输出将为 8。

正如我们所知,对于给定的长方体周长,P = 4(长度 + 宽度 + 深度),对于面积,将是 A = 2(长度* 宽度 + 宽度*深度 + 长度 *深度),且体积为 V = (长度* 宽度*深度)

示例

 实时演示

#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);
}

输出

Maximum volume of the cuboid will be: 4.14815

更新于:18-Dec-2019

392 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始
广告