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

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。
四棱锥的体积 [金字塔的底部是正方形] = (1/3) * (b^2) * h
三棱锥的体积 [金字塔的底部是三角形] = (1/6) * a * b * h
五棱锥的体积 [金字塔的底部是五边形] = (5/6) * a * b * h
六棱锥的体积 [金字塔的底部是六边形] = a * b * h
以下是计算金字塔体积的代码:
# Python3 program to Volume of Pyramid
# Function to calculate
# Volume of Triangular Pyramid
def volumeTriangular(a, b, h):
return (0.1666) * a * b * h
# Function To calculate
# Volume of Square Pyramid
def volumeSquare(b, h):
return (0.33) * b * b * h
# Function To calculate Volume
# of Pentagonal Pyramid
def volumePentagonal(a, b, h):
return (0.83) * a * b * h
# Function To calculate Volume
# of Hexagonal Pyramid
def volumeHexagonal(a, b, h):
return a * b * h
# Driver Code
b = float(4)
h = float(9)
a = float(4)
print( "Volume of triangular base pyramid is ",
volumeTriangular(a, b, h) )
print( "Volume of square base pyramid is ",
volumeSquare(b, h) )
print( "Volume of pentagonal base pyramid is ",
volumePentagonal(a,b, h) )
print( "Volume of Hexagonal base pyramid is ",
volumeHexagonal(a, b, h))
# This code is contributed by rishabh_jain
输出:
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)
如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。
4714

被折叠的 条评论
为什么被折叠?



