Given the length of space diagonal of a cube as d. The task is to calculate the volume occupied by the cube with the given length of space diagonal. Space diagonal is a line connecting two vertices that are not on the same face.
Input: d = 5 Output: Volume of Cube: 24.0563 Input: d = 10 Output: Volume of Cube: 192.45
Volume of cube whose space diagonal is given:
Let d = the length of diagonal |AB| and
let a = the length of each side of the cube.
Pythagorus #1 in triangle ACD:
Pythagorus #2 in triangle ABC:
Now we can solve for a in terms of d:
This means that the volume V is:
Below is the required implementation:
Volume of Cube: 24.0563
Time Complexity: O(1)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Find the diagonal of the Cube
- Program for Volume and Surface Area of Cube
- Program for volume of Pyramid
- Calculate Volume of Dodecahedron
- Program to calculate volume of Ellipsoid
- Program to calculate volume of Octahedron
- Find the volume of rectangular right wedge
- Maximize volume of cuboid with given sum of sides
- Perfect Cube
- Program to find the Volume of an irregular tetrahedron
- Program to calculate area and volume of a Tetrahedron
- Program for Volume and Surface Area of Cuboid
- Program to find the Area and Volume of Icosahedron
- Calculate volume and surface area of a cone
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.