Q:

Write a program to find the Area of the Rectangular Prism

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the area of a rectangular prism in different programming languages, firstly we have to know about the rectangular prism and its area'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.

Area of Rectangular Prism

To calculate the surface area of rectangular prism, first we have to use the following formula:

 

Surface area of Rectangular Prism = 2 * ((l * h) + (w * h) + (l * w))  

Where, l, w, and h is the length, width, and 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 area 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 area of a rectangular prism .  
#include <stdio.h>  
float find_surface_area_of_Rectangular_prism(float l, float w, float h) // It is a function to find area   
{   
float surface_area_of_Rectangular_prism ;  
surface_area_of_Rectangular_prism =  2 * ((l * h) + (w * h) + (l * w)); // It is a formula for calculating the area of rectangular prism    
return(surface_area_of_Rectangular_prism );   
}   
int main()   
{   
float l = 4.55, w = 9.10, h = 10;  
printf("Surface area of the rectangular prism  is: %f", find_surface_area_of_Rectangular_prism(l,w,h));     
return 0;   
}  

 

Output of Above C program:

Surface area of the rectangular prism  is: 355.809998

 

Program 2: Write a Program in Java language:

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

 

Output of Above Java program:

Surface area of the rectangular prism  is: 355.809998

 

Program 3: Write a Program in PHP programming language.

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

 

Output of Above PHP program:

355.81

 

Program 4: Write a Program in Python programming language.

# This is a python program which finds the area of a rectangular prism .   
def find_surface_area_of_Rectangular_prism(l, w, h):  
    return ( 2 * ((l * h) + (w * h) + (l * w)) ) # It is a formula which finds the value of area.  
# main code begins   
l = 9   
w = 2   
h = 18  
print(find_surface_area_of_Rectangular_prism(l,w, h) )  

 

Output of Above Python program:

432

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 Surface Area of a Tria... >>
<< Write a program to find the Surface Area of the Pe...