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

程式碼邏輯 − 計算四面體面積和體積的程式碼使用 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