PHP 金字塔体积计算程序(Program for volume of Pyramid)

 金字塔是一种三维几何形状,由多边形的所有角连接到中心顶点而形成。 
金字塔有很多种类型,通常以其基底类型命名。下面我们来看看一些常见的金字塔类型。

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。

四棱锥的体积 [金字塔的底部是正方形] = (1/3) * (b^2) * h 
三棱锥的体积 [金字塔的底部是三角形] = (1/6) * a * b * h 
五棱锥的体积 [金字塔的底部是五边形] = (5/6) * a * b * h 
六棱锥的体积 [金字塔的底部是六边形] = a * b * h

以下是计算金字塔体积的代码:

<?php
// PHP program to find the volume.

// Function to find the volume 
// of triangular pyramid
function volumeTriangular($a, $b, $h)
{
    $vol = (0.1666) * $a * $b * $h;
    return $vol;
}

// Function to find the
// volume of square pyramid
function volumeSquare($b, $h)
{
    $vol = (0.33) * $b * $b * $h;
    return $vol;
}

// Function to find the volume 
// of pentagonal pyramid
function volumePentagonal($a, $b, $h)
{
    $vol = (0.83) * $a * $b * $h;
    return $vol;
}

// Function to find the volume 
// of hexagonal pyramid
function volumeHexagonal($a, $b, $h)
{
    $vol = $a * $b * $h;
    return $vol;
}

// Driver Code
$b = 4; $h = 9; $a = 4;
echo ("Volume of triangular base pyramid is ");
echo( volumeTriangular($a, $b, $h));
echo("\n");
echo ("Volume of square base pyramid is ");
echo( volumeSquare($b, $h));
echo("\n");
echo ("Volume of pentagonal base pyramid is ");
echo(volumePentagonal($a, $b, $h));
echo("\n");
echo("Volume of Hexagonal base pyramid is ");
echo(volumeHexagonal($a, $b, $h));

// This code is contributed by vt_m 
?>

输出:

Volume of triangular base pyramid is(三角形底面金字塔的体积为) 23.9904

Volume of square  base pyramid is(正方形底面金字塔的体积为) 47.52

Volume of pentagonal base pyramid is(五角形底面金字塔的体积为) 119.52

Volume of Hexagonal base pyramid is(六角形底面金字塔的体积为) 144

时间复杂度:O(1)

辅助空间:O(1)

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hefeng_aspnet

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值