Program to calculate volume of Octahedron

21 Jun, 2022
Given the side of the Octahedron then calculate the volume of Octahedron.Examples:  
Input : 3
Output : 12.7279

Input : 7
Output : 161.692
 
A regular Octahedron has eight faces,twelve edges and six vertices. It has eight triangles with edges of equal length and effectively two square pyramids meeting at their bases. 
Image Source : Wikimedia 
Properties of Octahedron: Number of faces: 8 Number of edges: 12 Number of vertices: 6 Volume = √2/3 × a3 where a is the side of Octahedron  
 
CPP
Java
Python3
C#
PHP
Javascript
// CPP Program to calculate// volume of Octahedron#include <bits/stdc++.h>using namespace std; // utility Functiondouble vol_of_octahedron(double side){    return ((side*side*side)*(sqrt(2)/3));} // Driver Functionint main(){    double side = 3;    cout << "Volume of octahedron ="         << vol_of_octahedron(side)         << endl;}
// Java Program to calculate// volume of Octahedron import java.io.*;class GFG{    public static void main (String[] args)      {          // Driver Function         double side = 3;        System.out.print("Volume of octahedron = ");        System.out.println(vol_of_octahedron(side));       }     // utility Function    static double vol_of_octahedron(double side)      {         return ((side*side*side)*(Math.sqrt(2)/3));      }} // This code is contributed// by Azkia Anam.
# Python3 Program to calculate# volume of Octahedron import math # utility Functiondef vol_of_octahedron(side):    return ((side*side*side)*(math.sqrt(2)/3)) # Driver Functionside = 3print("Volume of octahedron =",      round(vol_of_octahedron(side),4)) # This code is contributed# by Azkia Anam.
// C# Program to calculate// volume of Octahedronusing System; class GFG{    public static void Main ()    {        // Driver Function        double side = 3;        Console.Write("Volume of octahedron = ");        Console.WriteLine(vol_of_octahedron(side));     }     // utility Function    static double vol_of_octahedron(double side)    {        return ((side*side*side)*(Math.Sqrt(2)/3));    }} // This code is contributed// by vt_m.
<?php// PHP Program to calculate// volume of Octahedron // utility Functionfunction vol_of_octahedron( $side){    return (($side * $side *             $side) * (sqrt(2) / 3));}     // Driver Function    $side = 3;    echo ("Volume of octahedron =");    echo(vol_of_octahedron($side));         // This code is contributed// by vt_m.?>
<script>// javascript Program to calculate// volume of Octahedron // utility Functionfunction vol_of_octahedron( side){    return ((side*side*side)*(Math.sqrt(2)/3));} // Driver Function    let side = 3;    document.write("Volume of octahedron = " +    vol_of_octahedron(side).toFixed(4));         // This code is contributed by gauravrajput1</script>
Output:  
 Volume of octahedron = 12.7279
Time complexity : O(1) Auxiliary Space : O(1)
vt_m
GauravRajput1
krishnav4
area-volume-programs
Geometric
School Programming
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program for distance between two points on earth
Find if two rectangles overlap
Check whether triangle is valid or not if sides are given
Line Clipping | Set 1 (Cohen–Sutherland Algorithm)
Program for Point of Intersection of Two Lines
Python Dictionary
Reverse a string in Java
Arrays in C/C++
Introduction To PYTHON
Interfaces in Java