求C#中圆柱的表面积和体积运算的程序代码,谢谢
答案:1 悬赏:40 手机版
解决时间 2021-03-28 12:33
- 提问者网友:锁深秋
- 2021-03-27 19:30
求C#中圆柱的表面积和体积运算的程序代码,谢谢
最佳答案
- 五星知识达人网友:底特律间谍
- 2021-03-27 20:25
真不会自己写?
计算面积:
public double calculateCylinderArea(double r,double h)
{
double cylinderArea = 0;
cylinderArea = Math.Pow(r, 2) * Math.PI * h;
return cylinderArea;
}计算体积
public double calculateCylinderVolume(double r,double h)
{
double CylinderVolume = 0;
CylinderVolume = 2 * Math.PI * Math.Pow(r, 2) + 2 * Math.PI * r * h;
return CylinderVolume;
}追问PI可以直接用吗?要不要声明一个标识符常量?const double PI=3.14159,谢谢。追答这个Math.PI本身就是Math类声明的常量,你可以打印到屏幕查看下
,自己声明也能用
计算面积:
public double calculateCylinderArea(double r,double h)
{
double cylinderArea = 0;
cylinderArea = Math.Pow(r, 2) * Math.PI * h;
return cylinderArea;
}计算体积
public double calculateCylinderVolume(double r,double h)
{
double CylinderVolume = 0;
CylinderVolume = 2 * Math.PI * Math.Pow(r, 2) + 2 * Math.PI * r * h;
return CylinderVolume;
}追问PI可以直接用吗?要不要声明一个标识符常量?const double PI=3.14159,谢谢。追答这个Math.PI本身就是Math类声明的常量,你可以打印到屏幕查看下
,自己声明也能用
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯