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

金字塔是一种三维几何形状,由多边形的所有角连接到中心顶点而形成。

金字塔有很多种类型,通常以其基底类型命名。下面我们来看看一些常见的金字塔类型。

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

四棱锥的体积 [金字塔的底部是正方形] = (1/3) * (b^2) * h

三棱锥的体积 [金字塔的底部是三角形] = (1/6) * a * b * h

五棱锥的体积 [金字塔的底部是五边形] = (5/6) * a * b * h

六棱锥的体积 [金字塔的底部是六边形] = a * b * h

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

// C# Program for volume of Pyramid.

using System;

class GFG

{

// Function to find the volume of

// triangular pyramid

public static float volumeTriangular(int a,

int b,

int h)

{

float vol = (float)(0.1666) * a * b * h;

return vol;

}

// Function to find the volume

// of square pyramid

public static float volumeSquare(int b,

int h)

{

float vol = (float)(0.33) * b * b * h;

return vol;

}

// Function to find the volume

// of pentagonal pyramid

public static float volumePentagonal(int a,

int b,

int h)

{

float vol = (float)(0.83) * a * b * h;

return vol;

}

// Function to find the volume

// of hexagonal pyramid

public static float volumeHexagonal(int a,

int b,

int h)

{

float vol = (float)a * b * h;

return vol;

}

// Driver Code

public static void Main()

{

int b = 4, h = 9, a = 4;

Console.WriteLine("Volume of triangular"+

" base pyramid is " +

volumeTriangular(a, b, h));

Console.WriteLine("Volume of square "+

"base pyramid is " +

volumeSquare(b, h));

Console.WriteLine("Volume of pentagonal"+

" base pyramid is " +

volumePentagonal(a, b, h));

Console.WriteLine("Volume of Hexagonal"+

" base pyramid is " +

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)

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

相关推荐
曹牧2 小时前
C#:姓名脱敏
开发语言·c#
缺点内向2 小时前
C# 中 Word 文档目录的插入与删除指南
开发语言·c#·word·.net
czhc11400756632 小时前
C# 1120抽象类 static
java·开发语言·c#
追逐时光者2 小时前
C# 中 ?、??、??=、?: 、?. 、?[] 各种问号的用法和说明
c#
唐青枫3 小时前
告别 if-else:C#.NET 模式匹配让代码更优雅的正确方式
c#·.net
Eiceblue12 小时前
通过 C# 将 HTML 转换为 RTF 富文本格式
开发语言·c#·html
IUGEI12 小时前
synchronized的工作机制是怎样的?深入解析synchronized底层原理
java·开发语言·后端·c#
czhc114007566315 小时前
C# 1124 接收
开发语言·c#
时光追逐者16 小时前
C#/.NET/.NET Core技术前沿周刊 | 第 62 期(2025年11.17-11.23)
c#·.net·.netcore
司铭鸿16 小时前
祖先关系的数学重构:从家谱到算法的思维跃迁
开发语言·数据结构·人工智能·算法·重构·c#·哈希算法