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)

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

相关推荐
SunnyDays10111 小时前
使用 C# 添加、修改和删除 Excel VBA 宏 (无需 Microsoft Office Interop)
c#·excel··vba
影寂ldy1 小时前
C# 多接口、同名冲突、显式实现、接口继承 完整笔记
java·笔记·c#
诸葛大钢铁1 小时前
如何降低Word文件的体积?压缩Word文件的三种方法
开发语言·c#
专注VB编程开发20年1 小时前
阿里通义灵码插件安装失败
开发语言·ide·c#·visual studio
影寂ldy2 小时前
C# 泛型方法
java·前端·c#
caimouse2 小时前
Godot 4.7 内嵌 C# 模块切换到 .NET 9.0 编译指南
c#·.net·godot
z落落11 小时前
C# 泛型方法(原理、类型推断、多泛型参数)+泛型效率(普通类型 VS Object装箱 VS 泛型)
开发语言·c#
rockey62712 小时前
基于AScript的SQL脚本语言发布啦!
sql·c#·.net·script·expression·动态脚本
z落落13 小时前
C# 四种特殊类:抽象类、密封类、静态类、部分类
开发语言·c#
王cb15 小时前
WinRT Server and Client c#
开发语言·c#