Program to find the Volume of a Triangular Prism - GeeksforGeeks

17 Mar, 2021
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++
Java
Python3
C#
PHP
Javascript
// CPP program to find the volume// of the triangular prism#include <bits/stdc++.h>using namespace std; // function to find the Volume// of triangular prismfloat findVolume(float l, float b, float h){    // formula to find Volume    float volume = (l * b * h) / 2;     return volume;} // Driver Codeint main(){    float l = 18, b = 12, h = 9;     // function calling    cout << "Volume of triangular prism: "         << findVolume(l, b, h);     return 0;}
// Java program to find the volume// of the triangular prismimport java.io.*; class GFG {     // function to find the Volume    // of triangular prism    static float findVolume(float l, float b, float h)    {        // formula to find Volume        float volume = (l * b * h) / 2;         return volume;    }     // Driver code    public static void main(String[] args)    {        float l = 18, b = 12, h = 9;         // function calling        System.out.println("Volume of triangular prism: "                           + findVolume(l, b, h));    }}
# Python3 program to find the volume# of the triangular prism # function to find the Volume# of triangular prismdef findVolume(l, b, h) :     # formula to find Volume    return ((l * b * h) / 2) # Driver Codel = 18b = 12h = 9     # function callingprint("Volume of triangular prism: ",                findVolume(l, b, h))
// C# program to find the volume// of the triangular prismusing System; class GFG {     // function to find the Volume    // of triangular prism    static float findVolume(float l, float b, float h)    {        // formula to find Volume        float volume = (l * b * h) / 2;         return volume;    }     // Driver code    static public void Main()    {        float l = 18, b = 12, h = 9;         // function calling        Console.WriteLine("Volume of triangular prism: "                          + findVolume(l, b, h));    }}
<?php// PHP program to find the volume// of the triangular prism // function to find the Volume// of triangular prismfunction findVolume($l, $b, $h){    // formula to find Volume    $volume = ($l * $b * $h) / 2;         return $volume;} // Driver Code$l = 18; $b = 12; $h = 9;     // function callingecho "Volume of triangular prism: "    . findVolume($l, $b, $h); ?>
<script>// Javascript program to find the volume// of the triangular prism // function to find the Volume// of triangular prismfunction findVolume( l,  b, h){     // formula to find Volume    let volume = (l * b * h) / 2;     return volume;} // Driver Code  let l = 18, b = 12, h = 9;     // function calling    document.write( "Volume of triangular prism: " + findVolume(l, b, h));     // This code is contributed by todaysgaurav </script>
Volume of triangular prism: 972
 
todaysgaurav
area-volume-programs
math
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program for distance between two points on earth
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
Line Clipping | Set 1 (Cohen–Sutherland Algorithm)
Convex Hull | Set 2 (Graham Scan)
Check whether a given point lies inside a triangle or not
Program for Fibonacci numbers
C++ Data Types
Write a program to print all permutations of a given string
Set in C++ Standard Template Library (STL)
Coin Change | DP-7