📜  求三角棱镜体积的程序

📅  最后修改于: 2021-10-23 08:41:39             🧑  作者: 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