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

代碼邏輯 − 計算四面體面積和體積的代碼使用 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP