C++ 代码示例:计算圆柱体的体积和表面积
#include<iostream>
using namespace std;
double bottomarea(double r){
//计算圆柱体的底面积
return 3.14 * r * r;
}
double volume(double r, double h){
//调用底面积函数,计算圆柱体的体积
return bottomarea(r) * h;
}
double surarea(double r, double h){
//计算圆柱体的表面积
return 2 * 3.14 * r * h + 2 * bottomarea(r);
}
int main(){
double r, h;
cout << '请输入圆柱体的半径和高:';
cin >> r >> h;
cout << '圆柱体的体积为:' << volume(r, h) << endl;
cout << '圆柱体的表面积为:' << surarea(r, h) << endl;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/nu1c 著作权归作者所有。请勿转载和采集!