Program to calculate area and volume of a Tetrahedron - GeeksforGeeks

01 May, 2021
A Tetrahedron is simply a pyramid with a triangular base. It is a solid object with four triangular faces, three on the sides or lateral faces, one on the bottom or the base and four vertices or corners. If the faces are all congruent equilateral triangles, then the tetrahedron is called regular. 
The area of Tetrahedron can be found by using the formula : 
Area = sqrt(3)*(side*side)
Examples :  
Input : side = 3
Output : 15.5885

Input : side = 20
Output : 692.82
C++
Java
Python3
C#
PHP
Javascript
// C++ Program to Calculate// area of tetrahedron#include<iostream>#include<math.h>using namespace std;  //Utility Functiondouble area_of_tetrahedron(int side){    return (sqrt(3)*(side*side));} //Driver Codeint main(){    int side=3;    cout<< "Area of Tetrahedron ="        << area_of_tetrahedron(side);} // This code is contributed by anant321.
// Java Program to Calculate// area of tetrahedronimport java.util.*;import java.lang.*; class GFG {     // Utility Function    public static double area_of_tetrahedron(int side)    {        return (Math.sqrt(3) * (side * side));     }     // Driver code    public static void main(String[] args)    {        int side = 3;        System.out.println("Area of Tetrahedron ="                     + area_of_tetrahedron(side));    }}// This code is contributed// by Prasad Kshirsagar
# Python3 Program to# Calculate area of# tetrahedronimport math def area_of_tetrahedron(side):    return (math.sqrt(3) *           (side * side)); # Driver Codeside = 3;print("Area of Tetrahedron = ",       round(area_of_tetrahedron(side), 4)); # This code is contributed by mits
// C# Program to Calculate// area of tetrahedronusing System; class GFG{// Utility Functionpublic static double area_of_tetrahedron(int side){    return (Math.Sqrt(3) *           (side * side)); } // Driver codestatic public void Main (){    int side = 3;    Console.WriteLine("Area of Tetrahedron = " +                     area_of_tetrahedron(side));}} // This code is contributed// by akt_mit
<?php// PHP Program to Calculate// area of tetrahedron function area_of_tetrahedron($side){    return (sqrt(3) * ($side * $side));}     // Driver Code    $side = 3;    echo "Area of Tetrahedron = ",          area_of_tetrahedron($side); // This code is contributed by aj_36.?>
<script>// javascript Program to Calculate// area of tetrahedron   // Utility Functionfunction area_of_tetrahedron( side){    return (Math.sqrt(3) * (side * side));} // Driver Codelet side = 3;document.write("Area of Tetrahedron ="+ area_of_tetrahedron(side).toFixed(4)); // This code contributed by aashish1995 </script
Output : 
Area of Tetrahedron =15.5885
The volume of the tetrahedron can be found by using the following formula : 
Volume = a3/(6√2)
Examples : 
Input : side = 3
Output : 3.18


Input : side = 20
Output : 942.81
C++
Java
Python3
C#
PHP
Javascript
// C++ code to find the volume of a tetrahedron#include <bits/stdc++.h>using namespace std; // Function to calculate volumedouble vol_tetra(int side){    double volume = (pow(side, 3) /                    (6 * sqrt(2)));    return volume;} // Driver codeint main(){    int side = 3;    double vol = vol_tetra(side);    vol = (double)round(vol * 100) / 100;    cout << vol;     return 0;} // This code is contributed by suresh07
// Java code to find the volume of a tetrahedronimport java.io.*; class Tetrahedron {    // Function to calculate volume    static double vol_tetra(int side)    {        double volume = (Math.pow(side, 3) / (6 * Math.sqrt(2)));        return volume;    }     // Driver Code    public static void main(String[] args)    {        int side = 3;        double vol = vol_tetra(side);        vol = (double)Math.round(vol * 100) / 100;        System.out.println(vol);    }}
# Python code to find the volume of a tetrahedronimport mathdef vol_tetra(side):    volume = (side ** 3 / (6 * math.sqrt(2)))    return round(volume, 2) # Driver Codeside = 3vol = vol_tetra(side)print(vol)
// C# code to find the volume of a tetrahedronusing System; class Tetrahedron {    // Function to calculate volume    static double vol_tetra(int side)    {        double volume = (Math.Pow(side, 3) / (6 * Math.Sqrt(2)));        return volume;    }     // Driver Code    public static void Main()    {        int side = 3;        double vol = vol_tetra(side);        vol = (double)Math.Round(vol * 100) / 100;        Console.WriteLine(vol);    }} // This code is contributed// by vt_m.
<?php// PHP program to find the// volume of a tetrahedron // Function to calculate volumefunction vol_tetra($side){    $volume = (pow($side, 3) /                  (6 * sqrt(2)));    return $volume;} // Driver Code$side = 3;$vol = vol_tetra($side);echo $vol;     // This code is contributed by ajit?>
<script>// javascript code to find the volume of a tetrahedron function vol_tetra(side){    let volume = (Math.pow(side, 3) / (6 * Math.sqrt(2)));    return volume;} // Driver Codelet side = 3;let vol = vol_tetra(side);vol = Math.round(vol * 100) / 100;document.write(vol); // This code is contributed by gauravrajput1 </script>
Output : 
3.18
 
jit_t
Prasad_Kshirsagar
Mithun Kumar
aashish1995
GauravRajput1
suresh07
area-volume-programs
Geometric
Mathematical
School Programming
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Optimum location of point to minimize total distance
Given n line segments, find if any two segments intersect
Convex Hull using Divide and Conquer Algorithm
Polygon Clipping | Sutherland–Hodgman Algorithm
Program for Point of Intersection of Two Lines
Program for Fibonacci numbers
Write a program to print all permutations of a given string
Set in C++ Standard Template Library (STL)
C++ Data Types
Coin Change | DP-7