在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
热门推荐
5 初八祝福语简短语
10 职场离职文案祝福语简短
11 锡婚祝福语简短霸气
12 庆双节祝福语简短
13 月子小孩祝福语大全简短
14 比赛结束花束祝福语简短
15 虎年新年专属祝福语简短
16 虎年送火腿祝福语简短
17 给长辈祝福语简短大全
18 小姨生日祝福语简短独特