在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
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短