Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

โปรแกรมคำนวณพื้นที่และปริมาตรทรงสี่หน้า (Tetrahedron)


ทรงสี่หน้า (tetrahedron) เป็นพีระมิดที่ฐานเป็นสามเหลี่ยม คือมีฐานสามเหลี่ยม และทุกด้านเป็นสามเหลี่ยม สามเหลี่ยมทั้ง 3 รวมกันที่จุดยอด

โปรแกรมคำนวณพื้นที่และปริมาตรทรงสี่หน้า (Tetrahedron)

ตรรกะโค้ด - ใช้ math library หาค่ากำลังสองและรากที่สองด้วย sqrt และ pow พื้นที่ใช้สูตร (√3×a×a) ปริมาตรใช้สูตร (a³/(6×√2))

ตัวอย่าง

#include <stdio.h> #include <math.h> int main() { int a = 5; float area, volume; printf("Program to find area and volume of Tetrahedron\n"); printf("The side of Tetrahedron is %d \n", a); area = (sqrt(3)*(a*a)); printf("The area of Tetrahedron is %f \n", area); volume = (pow(a,3) / (6 * sqrt(2))); printf("The volume of Tetrahedron is %f \n", 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