使用function函数,Math对象计算圆柱体的体积
1,首先需要知道圆柱体的体积公式 : V=Πr²h && V=sh
2, 尝试编写
eg:
<!Doctype html>
<html>
<head>
<meta charset="uft-8" />
<title>计算一个圆柱体的体积</title>
</head>
<body>
<script>
function bulk(r,h) //设置两个参数 为圆柱体的直径和高
{
document.write("圆柱体的体积为:" +Math.ceil (Math.PI*(Math.pow((r/2),2))*h));
//使用Math.ceil 向上取整 Math.pow 表示平方
}
bulk(4,3);//输入圆柱体的直径和高
</script>
<body>
</html>
运行结果: