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
#include <bits/stdc++.h>
using namespace std;
double vol_of_octahedron( double side)
{
return ((side*side*side)*( sqrt (2)/3));
}
int main()
{
double side = 3;
cout << "Volume of octahedron ="
<< vol_of_octahedron(side)
<< endl;
}
|
Java
import java.io.*;
class GFG
{
public static void main (String[] args)
{
double side = 3 ;
System.out.print( "Volume of octahedron = " );
System.out.println(vol_of_octahedron(side));
}
static double vol_of_octahedron( double side)
{
return ((side*side*side)*(Math.sqrt( 2 )/ 3 ));
}
}
|
Python3
import math
def vol_of_octahedron(side):
return ((side * side * side) * (math.sqrt( 2 ) / 3 ))
side = 3
print ( "Volume of octahedron =" ,
round (vol_of_octahedron(side), 4 ))
|
C#
using System;
class GFG
{
public static void Main ()
{
double side = 3;
Console.Write( "Volume of octahedron = " );
Console.WriteLine(vol_of_octahedron(side));
}
static double vol_of_octahedron( double side)
{
return ((side*side*side)*(Math.Sqrt(2)/3));
}
}
|
PHP
<?php
function vol_of_octahedron( $side )
{
return (( $side * $side *
$side ) * (sqrt(2) / 3));
}
$side = 3;
echo ( "Volume of octahedron =" );
echo (vol_of_octahedron( $side ));
?>
|
Javascript
<script>
function vol_of_octahedron( side)
{
return ((side*side*side)*(Math.sqrt(2)/3));
}
let side = 3;
document.write( "Volume of octahedron = " +
vol_of_octahedron(side).toFixed(4));
</script>
|
Output:
Volume of octahedron = 12.7279
Time complexity : O(1)
Auxiliary Space : O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!