In mathematics, a triangular prism is a three-dimensional solid shape with two identical ends connected by equal parallel lines, and have 5 faces, 9 edges, and 6 vertices.

where “b” is the length of the base, “h” is the height of the triangle, “s1, s2, s3” are the respective length of each side of the triangle, and H is the height of the prism (which is also the length of the rectangle).
Given the base, the height of the triangle, height of prism and the length of each side of triangle base and the task is to calculate the surface area of the triangular prism.
Examples:
Input: b = 3, h = 4, s1 = 3, s2 = 6, s3 = 6, Ht = 8
Output: The area of triangular prism is 132.000000
Input: b = 2, h = 3, s1 = 4, s2 = 5, s3 = 6, Ht = 8
Output: The area of triangular prism is 126.000000
Formula for calculating the surface area:
As stated above, the prism contains two triangles of the area (1/2)*(b)*(h) and three rectangles of the area H*s1, H*s2 and H*s3.
Now after adding all the terms we get the total surface area:
SA = b * h + (s1 + s2 + s3 ) * H
C++
#include <bits/stdc++.h>
using namespace std;
void Calculate_area()
{
float b = 3, h = 4, s1 = 3, s2 = 6;
float s3 = 6, Ht = 8, SA;
SA = b * h + (s1 + s2 + s3) * Ht;
cout << "The area of triangular prism is : " << SA;
}
int main()
{
Calculate_area();
return 0;
}
|
C
#include <stdio.h>
void Calculate_area()
{
float b = 3, h = 4, s1 = 3, s2 = 6;
float s3 = 6, Ht = 8, SA;
SA = b * h + (s1 + s2 + s3) * Ht;
printf ( "The area of triangular prism is : %f" , SA);
}
int main()
{
Calculate_area();
return 0;
}
|
Java
import java.util.Scanner;
public class Prism {
public static void Calculate_area()
{
double b = 3 , h = 4 , s1 = 3 , s2 = 6 ;
double s3 = 6 , Ht = 8 , SA;
SA = b * h + (s1 + s2 + s3) * Ht;
System.out.printf( "The area of triangular prism is : %f" , SA);
}
public static void main(String[] args)
{
Calculate_area();
}
}
|
Python3
def Calculate_area():
b = 3
h = 4
s1 = 3
s2 = 6
s3 = 6
Ht = 8
SA = b * h + (s1 + s2 + s3) * Ht
print ( "The area of triangular prism is :" ,SA)
if __name__ = = '__main__' :
Calculate_area()
|
C#
using System;
public class Prism {
static void Calculate_area()
{
double b = 3, h = 4, s1 = 3, s2 = 6;
double s3 = 6, Ht = 8, SA;
SA = b * h + (s1 + s2 + s3) * Ht;
Console.WriteLine( "The area of triangular prism is : " + SA);
}
static public void Main(String[] args)
{
Calculate_area();
}
}
|
PHP
<?php
function Calculate_area()
{
$b = 3; $h = 4;
$s1 = 3; $s2 = 6;
$s3 = 6; $Ht = 8; $SA ;
$SA = $b * $h + ( $s1 +
$s2 + $s3 ) * $Ht ;
echo "The area of triangular" .
" prism is : " , $SA ;
}
Calculate_area();
?>
|
Javascript
<script>
function Calculate_area()
{
let b = 3, h = 4, s1 = 3, s2 = 6;
let s3 = 6, Ht = 8, SA;
SA = b * h + (s1 + s2 + s3) * Ht;
document.write( "The area of triangular prism is : " +SA);
}
Calculate_area();
</script>
|
OutputThe area of triangular prism is : 132
Time complexity: O(1)
Auxiliary Space: O(1)