c++求三个圆柱体体积
时间: 2024-01-23 07:13:06 浏览: 153
以下是C++求三个圆柱体体积的代码示例:
```cpp
#include <iostream>
#include <cmath>
using namespace std;
double Cylinder(double r, double h); // 函数声明
int main() {
double radius1, height1, radius2, height2, radius3, height3;
cout << "请输入第一个圆柱体的半径和高:\n";
cin >> radius1 >> height1;
cout << "请输入第二个圆柱体的半径和高:\n";
cin >> radius2 >> height2;
cout << "请输入第三个圆柱体的半径和高:\n";
cin >> radius3 >> height3;
double volume1 = Cylinder(radius1, height1);
double volume2 = Cylinder(radius2, height2);
double volume3 = Cylinder(radius3, height3);
cout << "第一个圆柱体的体积为:" << volume1 << endl;
cout << "第二个圆柱体的体积为:" << volume2 << endl;
cout << "第三个圆柱体的体积为:" << volume3 << endl;
}
// 计算圆柱体体积的函数
double Cylinder(double r, double h) {
return r * r * M_PI * h;
}
```
阅读全文