Dado el lado del octaedro, calcule el volumen del octaedro.
Ejemplos:
Input : 3 Output : 12.7279 Input : 7 Output : 161.692
Un octaedro regular tiene ocho caras, doce aristas y seis vértices. Tiene ocho triángulos con aristas de igual longitud y efectivamente dos pirámides cuadradas que se unen en sus bases.
Fuente de la imagen: Wikimedia
Propiedades del Octaedro:
Número de caras: 8
Número de aristas: 12
Número de vértices: 6
Volumen = √2/3 × a 3 donde a es el lado del Octaedro
CPP
// CPP Program to calculate // volume of Octahedron #include <bits/stdc++.h> using namespace std; // utility Function double vol_of_octahedron(double side) { return ((side*side*side)*(sqrt(2)/3)); } // Driver Function int main() { double side = 3; cout << "Volume of octahedron =" << vol_of_octahedron(side) << endl; }
Java
// 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
# Python3 Program to calculate # volume of Octahedron import math # utility Function def vol_of_octahedron(side): return ((side*side*side)*(math.sqrt(2)/3)) # Driver Function side = 3 print("Volume of octahedron =", round(vol_of_octahedron(side),4)) # This code is contributed # by Azkia Anam.
C#
// C# Program to calculate // volume of Octahedron using 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 // PHP Program to calculate // volume of Octahedron // utility Function function 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. ?>
Javascript
<script> // javascript Program to calculate // volume of Octahedron // utility Function function 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>
Producción:
Volume of octahedron = 12.7279
Complejidad temporal : O(1)
Espacio auxiliar : O(1)