Q:

Write a program to find the Surface Area of a Triangular Prism

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the area of a triangular prism in different programming languages, firstly we have to know about the triangular prism and its formula.

What is Triangular Prism?

Triangular Prism is a 3-D shape, which has 5 faces, 6 vertices, and 9 edges.

Area of Triangular Prism

As, the prism contains 2 triangles and 3 rectangles. So,

 

Surface area of Triangular Prism = (b * h) + (L * (s1 + s2 + s3))  

Where, b is the bottom edge of base triangle, L is the prism length, h is the height of base triangle, and s1, s2, and s3 are the three edges of base triangle.  

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 triangular 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 triangular prism.  
#include <stdio.h>  
float find_area_of_Triangular_prism(float L, float b, float h, float s1, float s2, float s3) // It is a function to find area   
{   
float area_of_Triangular_prism ;  
area_of_Triangular_prism = (b * h) + (L * (s1 + s2 + s3)); // It is a formula for calculating the area of triangular prism    
return (area_of_Triangular_prism );   
}   
float main()   
{   
float b = 9, h = 5, s1 = 3;   
float s3 = 6, s2 = 8, L = 8;  
printf("Surface area of the triangular prism  is: %f", find_area_of_Triangular_prism(L, b, h, s1, s2, s3));     
return 0;   
}  

 

Output of Above C program:

Surface area of the triangular prism  is: 181.000000

 

Program 2: Write a Program in Java language:

// This is a Java program which finds the area of a triangular prism .  
class findarea {   
static float find_area_of_Triangular_prism(float L, float b, float h, float s1, float s2, float s3)   
{    
float area_of_Triangular_prism ;  
area_of_Triangular_prism = (b * h) + (L * (s1 + s2 + s3)); // It is a formula for calculating the area of triangular prism    
return(area_of_Triangular_prism);   
}   
// Driver method   
public static void main(String[] args)   
{   
float b = 3, h = 4, s1 = 3, s2 = 6;   
float s3 = 6, L = 8;  
System.out.println("The area of a triangular prism  is:");  
System.out.println(find_area_of_Triangular_prism(L, b, h, s1, s2, s3));   
}   
}  

 

Output of Above Java program:

The area of a triangular prism  is:
132.0

 

Program 3: Write a Program in PHP programming language.

<?php   
// This is a PHP program which finds the area of a triangular prism.    
// Function to find area   
function find_area_of_Triangular_prism($L, $b, $h, $s1, $s2, $s3)   
{     
$area_of_Triangular_prism  =($b * $h) + ($L * ($s1 + $s2 + $s3)); // It is an statement which uses a forumla to find the surface area and store the value in the area_of_triangular prism variable.   
return ($area_of_Triangular_prism);   
}   
$b = 4;   
$h = 4;    
$s1 = 6;   
$s2 = 9;   
$s3 = 2;   
$L = 1;  
echo find_area_of_Triangular_prism($L, $b, $h, $s1, $s2, $s3);   
?>  

 

Output of Above PHP program:

33

 

Program 4: Write a Program in Python programming language.

# This is a python program which finds the area of a triangular prism .   
def find_area_of_Triangular_prism(L, b, h, s1, s2 ,s3):  
    return ( (b * h) + (L * (s1 + s2 + s3)) ) # It is a formula which finds the value of area.  
# main code begins   
b = 4;   
h = 4;    
s1 = 6;   
s2 = 9;   
s3 = 2;   
L = 1;  
print(find_area_of_Triangular_prism(L, b, h, s1, s2, s3) )  

 

Output of Above Python program:

33

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 Hexagonal Pris... >>
<< Write a program to find the Area of the Rectangula...