Q:

Program to find the volume of the cube

belongs to collection: Basic Programs

0

Volume of a cube = side * side * side.   

The cube has all the edges of the same length. The volume of a cube can be calculated by multiplying the length of an edge by itself twice. So if the length of an edge is 4, the volume is 4 x 4 x 4 = 64

Algorithm

  1. Define the value of variable 'a' as the length of an edge of the cube.
  2. Multiply 'a' with 'a' and again multiple the results with 'a' to obtain the volume of the cube.
  3. Define the variable volume_cube and assign the volume of the cube to it.

Complexity

O(1)

Input:

side = 4  

Output:

Volume of cube = side3
               = 43
               = 64

All Answers

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

C Program

#include <stdio.h>  
  
int main()  
{  
    int a=4;  
    int volume=a*a*a;  
    printf("Volume of the cube=%d",volume);  
}  

 

Output:

Volume of the cube=64  

 

PHP Program

<?php    
   $a=4;  
    $volume=$a*$a*$a;  
    echo "Volume of the cube=";  
    echo $volume;  
?> 

   

Output:

Volume of the cube=64  

 

Java Program

public class cube{  
    public static void main(String args[])  
    {  
    int a=4;  
    int volume=a*a*a;  
        System.out.println("Volume ot the cube="+volume);  
     }  
}

  

Output:

Volume ot the cube=64

 

C# Program

using System;                     
public class Program  
{  
    public static void Main()  
    {  
int a=4;  
int volume=a*a*a;  
      
   Console.WriteLine("Volume of cube="+volume);  
    }  
} 

 

Output:

Volume of cube=64

 

Python Program

a=4  
volume=a*a*a  
print("volume of the cube="+str(volume))  

 

Output:

volume of the cube=64  

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

total answers (1)

Program to find the volume of the cylinder... >>
<< Program to find the volume of the cone...