Q:

Write a program to find the Volume of Octahedron

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the volume of an octahedron in different programming languages, firstly we have to know about an octahedron and its formula.

What is Octahedron?

Octahedron is a regular polyhedron shape, which has six vertices, twelve edges, and eight faces.

Volume of Octahedron

 

Volume of Octahedron = ((√2) / 3) * (a * a * a)  

Where, a is the side of an octahedron.  

All Answers

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

Program of calculating the volume of an octahedron in different Programming languages

Program 1: Write a Program in C language:

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

 

Output of Above C program:

Enter the side of the octahedron:5
Surface area of the octahedron is: 58.925564

 

Program 2: Write a Program in Java language:

// This a  Java program which finds the volume of a octahedron.  
class findvolume {   
static double find_volume_of_octahedron(float a)   
{    
double volume_of_octahedron;  
volume_of_octahedron= (Math.sqrt(2) / 3) * (a * a * a) ; // It is a formula for calculating the volume of octahedron   
return(volume_of_octahedron);   
}   
// Driver method   
public static void main(String[] args)   
{   
float side = 120;   
System.out.println("The volume of a octahedron is:");  
System.out.println(find_volume_of_octahedron(side));   
}   
}  

 

Output of Above Java program:

The volume of a octahedron is:
814587.0119269028

 

Program 3: Write a Program in PHP programming language.

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

 

Output of Above PHP program:

471.40452079103

 

Program 4: Write a Program in Python programming language.

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

 

Output of Above Python program:

471404.5207910317

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

total answers (1)

Miscellaneous Programs Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a program to find the Area of Tetrahedron... >>
<< Write a program to find the Area of an Icosahedron...