c++求三个圆柱体的体积
时间: 2024-06-13 21:06:52 浏览: 83
圆柱体体积
5星 · 资源好评率100%
以下是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;
return 0;
}
//调用函数
double Cylinder(double r, double h) {
return r*r*M_PI*h;
}
```
阅读全文