Program to find the Volume of a Triangular Prism
Given the length, width, and height of a triangular prism, the task is to find the volume of the triangular prism.
Examples:
Input: l = 18, b = 12, h = 9
Output: Volume of triangular prism: 972
Input: l = 10, b = 8, h = 6
Output: Volume of triangular prism: 240
In mathematics, a triangular prism is a three-dimensional solid shape with two identical ends connected by equal parallel lines. The triangular prism contains 5 faces, 9 edges, and 6 vertices.
Formula to find the volume of triangular prism:
Volume = ( l * b * h ) / 2
C++
#include <bits/stdc++.h>
using namespace std;
float findVolume( float l, float b, float h)
{
float volume = (l * b * h) / 2;
return volume;
}
int main()
{
float l = 18, b = 12, h = 9;
cout << "Volume of triangular prism: "
<< findVolume(l, b, h);
return 0;
}
|
Java
import java.io.*;
class GFG {
static float findVolume( float l, float b, float h)
{
float volume = (l * b * h) / 2 ;
return volume;
}
public static void main(String[] args)
{
float l = 18 , b = 12 , h = 9 ;
System.out.println( "Volume of triangular prism: "
+ findVolume(l, b, h));
}
}
|
Python3
def findVolume(l, b, h) :
return ((l * b * h) / 2 )
l = 18
b = 12
h = 9
print ( "Volume of triangular prism: " ,
findVolume(l, b, h))
|
C#
using System;
class GFG {
static float findVolume( float l, float b, float h)
{
float volume = (l * b * h) / 2;
return volume;
}
static public void Main()
{
float l = 18, b = 12, h = 9;
Console.WriteLine( "Volume of triangular prism: "
+ findVolume(l, b, h));
}
}
|
PHP
<?php
function findVolume( $l , $b , $h )
{
$volume = ( $l * $b * $h ) / 2;
return $volume ;
}
$l = 18; $b = 12; $h = 9;
echo "Volume of triangular prism: "
. findVolume( $l , $b , $h );
?>
|
Javascript
<script>
function findVolume( l, b, h)
{
let volume = (l * b * h) / 2;
return volume;
}
let l = 18, b = 12, h = 9;
document.write( "Volume of triangular prism: " + findVolume(l, b, h));
</script>
|
Output:
Volume of triangular prism: 972
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
09 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...