📜  查找三角棱镜体积的程序

📅  最后修改于: 2021-04-24 05:21:01             🧑  作者: Mango

给定三棱柱的长度,宽度和高度,任务是找到三棱柱的体积。
例子:

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

在数学中,三棱柱是三维立体形状,其两个相同的末端由相等的平行线连接。三角棱镜包含5个面,9个边和6个顶点。

三棱镜

查找三角棱镜体积的公式:

Volume = ( l * b * h ) / 2 
C++
// CPP program to find the volume
// of the triangular prism
#include 
using namespace std;
 
// function to find the Volume
// of triangular prism
float findVolume(float l, float b, float h)
{
    // formula to find Volume
    float volume = (l * b * h) / 2;
 
    return volume;
}
 
// Driver Code
int main()
{
    float l = 18, b = 12, h = 9;
 
    // function calling
    cout << "Volume of triangular prism: "
         << findVolume(l, b, h);
 
    return 0;
}


Java
// Java program to find the volume
// of the triangular prism
import 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
# Python3 program to find the volume
# of the triangular prism
 
# function to find the Volume
# of triangular prism
def findVolume(l, b, h) :
 
    # formula to find Volume
    return ((l * b * h) / 2)
 
# Driver Code
l = 18
b = 12
h = 9
     
# function calling
print("Volume of triangular prism: ",
                findVolume(l, b, h))


C#
// C# program to find the volume
// of the triangular prism
using 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


Javascript


输出:
Volume of triangular prism: 972