四面体的面积与体积的计算程序


四面体是一個底面為三角形的錐體,即它的底面是一個三角形,每個側面也是一個三角形。這三個三角形在一個點處會合。如圖所示,

代碼邏輯 − 計算四面體面積和體積的代碼使用 math 庫,通過 sqrt 和 pow 方法計算一個數的平方和平方根。為了計算面積,我們採取一個浮點數,並將表達式 “((sqrt(3)*a*a))” 的值賦予它。另一個變量獲取四面體體積的值,通過使用表達式,“(a*a*a/(6*(sqrt(2))))” 評估獲得。

示例

#include <stdio.h>
#include <math.h>
int main() {
   int a = 5;
   float area, volume;
   printf("Program to find area and volume of Tetrahedron
");    printf("The side of Tetrahedron is %d
", a);    area = (sqrt(3)*(a * a));    printf("The area of Tetrahedron is %f
", area);    volume = (pow(a, 3) / (6 * sqrt(2)));    printf("The volume of Tetrahedron is %f
", volume);    return 0; }

輸出

Program to find area and volume of Tetrahedron
The side of Tetrahedron is 5
The area of Tetrahedron is 43.301270
The volume of Tetrahedron is 14.731391

更新於: 2019 年 7 月 30 日

284 次瀏覽

开启你的 事业

完成课程,获得认证

开始学习
广告
© . All rights reserved.