Q:

Write a program to find the Volume of Tetrahedron

0

Before writing the program of calculating the volume of a tetrahedron in different programming languages, firstly we have to know about what is tetrahedron and its formula.

What is Tetrahedron?

Tetrahedron is simply a polyhedron shape, which has 4 triangular faces, four vertices, and six edges. If the faces are all congruent equilateral triangles, then the tetrahedron is called regular.

Volume of Tetrahedron

 

Volume of Tetrahedron = ((a * a * a ) / (6√2))  

Where, a is the side of an tetrahedron.  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program of calculating the volume of a tetrahedron in different Programming languages

Program 1: Write a Program in C language:

// This program which uses a function to find the volume of a tetrahedron.  
#include <stdio.h>  
float find_volume_of_tetrahedron(float a) // It is a function to find volume   
{   
float volume_of_tetrahedron;  
volume_of_tetrahedron=  ((a * a * a) / (6 * sqrt(2) )); // It is a formula for calculating the volume of tetrahedron   
return (volume_of_tetrahedron);   
}   
float main()   
{   
float side;  
printf("Enter the side of the tetrahedron:");   
scanf("%f",&side);  
printf("Surface area of the tetrahedron is: %f", find_volume_of_tetrahedron(side));     
return 0;   
}   

 

Output of Above C program:

Enter the side of the tetrahedron:5
Surface area of the tetrahedron is: 14.731391

 

Program 2: Write a Program in Java language:

// This a  Java program which finds the volume of a tetrahedron.  
import java.lang.Math;  
class findvolume {   
static double find_volume_of_tetrahedron(float a)   
{    
double volume_of_tetrahedron;  
volume_of_tetrahedron= ((a * a * a) / (6 * Math.sqrt(2) )); // It is a formula for calculating the volume of tetrahedron   
return(volume_of_tetrahedron);   
}   
// Driver method   
public static void main(String[] args)   
{   
float side = 5;   
System.out.println("The volume of a tetrahedron is:");  
System.out.println(find_volume_of_tetrahedron(side));   
}   
}  

 

Output of Above Java program:

The volume of a tetrahedron is:14.731391274719739

 

Program 3: Write a Program in PHP programming language.

<?php   
// This a  PHP program which finds the volume of a tetrahedron.    
// Function to find volume   
function find_volume_of_tetrahedron($a)   
{     
$volume_of_tetrahedron = (($a * $a * $a) / (6 * sqrt(2) )); // It is a formula which finds the volume and store the value in the volume_of_tetrahedron variable.   
return ($volume_of_tetrahedron);   
}   
$side = 5;  
echo find_volume_of_tetrahedron($side);   
  
?>  

 

Output of Above PHP program:

14.73

 

Program 4: Write a Program in Python programming language.

# This is a python program which finds the volume of a tetrahedron.   
from  math import sqrt  
def find_volume_of_tetrahedron(a):  
    return ( ((a * a * a) / (6 * sqrt(2) ))) # It is a formula which finds the value of volume.  
# main code begins   
side = 10  
print(find_volume_of_tetrahedron(side  

 

Output of Above Python program:

117.85113019775791

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now