Q:

Write a program to find the Volume of the Rectangular Prism

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the volume of a rectangular prism in different programming languages, firstly we have to know about the rectangular prism and its volume's formula.

What is Rectangular Prism?

Rectangular Prism is a 3-D shape, which has six faces, 8 vertices, and 12 edges. This object is similar to cuboids. All the faces of this shape are rectangle.

Volume of Rectangular Prism

To calculate the volume of rectangular prism, we have to use the following formula:

 

Volume of Rectangular Prism = (l * w * h)  

Where, h is the height of the rectangular prism  

All Answers

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

Program of calculating the volume of a rectangular prism in different Programming languages

Program 1: Write a Program in C language:

// This program which uses a function to find the volume of a rectangular prism .  
#include <stdio.h>  
float find_volume_of_Rectangular_prism(float l, float w, float h) // It is a function to find volume   
{   
float volume_of_Rectangular_prism ;  
volume_of_Rectangular_prism =  (l * w * h); // It is a formula for calculating the volume of rectangular prism    
return (volume_of_Rectangular_prism );   
}   
float main()   
{   
float l = 4.55, w = 9.10, h = 10 ;  
  
printf("Volume of the rectangular prism  is: %f", find_volume_of_Rectangular_prism(l, w, h));     
return 0;   
}  

 

Output of Above C program:

Volume of the rectangular prism is: 414.050018

 

Program 2: Write a Program in Java language:

// This is a Java program which finds the volume of a rectangular prism .  
class findarea {   
static float find_volume_of_Rectangular_prism( float l, float w, float h)   
{    
float volume_of_Rectangular_prism ;  
volume_of_Rectangular_prism = (l * w * h); // It is a formula for calculating the volume of rectangular prism    
return(volume_of_Rectangular_prism);   
}   
  
// Driver method   
public static void main(String[] args)   
{   
float l = 6, w = 9, h = 10 ;  
System.out.println("The volume of a rectangular prism  is:");  
System.out.println(find_volume_of_Rectangular_prism(l, w, h));   
}   
}  

 

Output of Above Java program:

The volume of a rectangular prism is:
540.0

 

Program 3: Write a Program in PHP programming language.

<?php   
// This PHP program which finds the volume of a rectangular prism.    
// Function to find volume   
function find_volume_of_Rectangular_prism($l, $w, $h)   
{     
$volume_of_Rectangular_prism = ($l * $w * $h); // It is an statement which uses a forumla to find the Volume and store the value in the volume_of_rectangular prism variable.   
return ($volume_of_Rectangular_prism);   
}   
$l = 4.55;  
$w = 9.10;   
$h = 10 ;  
echo find_volume_of_Rectangular_prism($l, $w, $h);   
?>  

 

Output of Above PHP program:

414.05

 

Program 4: Write a Program in Python programming language.

# This is a python program which finds the volume of a rectangular prism .   
def find_volume_of_Rectangular_prism(l, w, h):  
    return ( (l * w * h)) # It is a formula which finds the value of volume.  
# main code begins   
h = 4  
w = 8  
l = 10  
print(find_volume_of_Rectangular_prism(l, w, h) )  

 

Output of Above Python program:

320

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
Program to Convert centimeter to millimeter... >>
<< Write a Program to find the Volume of a Hexagonal ...