📜  求矩形右楔形的体积

📅  最后修改于: 2021-04-26 08:02:12             🧑  作者: Mango

右楔形是具有平行边三角形的楔形。它具有两个侧基ab ,顶边e和高度h 。任务是找到给定的矩形右楔块的体积。

矩形右楔

例子:

方法:

楔

Va是三角形金字塔的体积,即Va =(1/3)*三角形面积*(e – a)
三角形的面积=(1/2)* b * h
Va =(1/3)*((1/2)*(b * h *(e – a)))
Vb是三棱柱的体积,即Vb =横截面积*长度(侧面)
Vb =(1/2)*(b * h * a)

矩形右楔形的体积=(b * h / 6)*(2 * a + e),其中a和b是侧基,e是上边缘,h是矩形右楔形的高度。
下面是上述方法的实现:

C++
// CPP program to find volume of rectangular right wedge
#include 
using namespace std;
 
// function to return volume
//of rectangular right wedge
double volumeRec(double a,double b,double e,double h)
{
     
    return (((b * h )/ 6)*(2 * a + e));
}
 
// Driver code
int main()
{
    double a = 2;
    double b = 5;
    double e = 5;
    double h = 6;
    printf("Volume = %.1f",volumeRec(a, b, e, h));
    return 0;
}
 
// This code contributed by nidhiva


Java
// Java implementation of the approach
class GFG {
 
    // Function to return the volume
    // of the rectangular right wedge
    static double volumeRec(double a, double b, double e, double h)
    {
        return (((b * h) / 6) * (2 * a + e));
    }
 
    // Driver code
    public static void main(String[] args) throws java.lang.Exception
    {
        double a = 2, b = 5, e = 5, h = 6;
        System.out.print("Volume = " + volumeRec(a, b, e, h));
    }
}


Python3
# Python3 implementation of the approach
 
# Function to return the volume
# of the rectangular right wedge
def volumeRec(a, b, e, h) :
     
    return (((b * h) / 6) * (2 * a + e));
 
 
# Driver code
if __name__ == "__main__" :
     
    a = 2; b = 5; e = 5; h = 6;
     
    print("Volume = ",volumeRec(a, b, e, h));
     
# This code is contributed by AnkitRai01


C#
// C# implementation of the approach
using System;
 
class GFG
{
 
    // Function to return the volume
    // of the rectangular right wedge
    static double volumeRec(double a, double b,
                            double e, double h)
    {
        return (((b * h) / 6) * (2 * a + e));
    }
 
    // Driver code
    public static void Main()
    {
        double a = 2, b = 5, e = 5, h = 6;
        Console.WriteLine("Volume = " + volumeRec(a, b, e, h));
    }
}
 
// This code is contributed by vt_m.


Javascript


输出:
Volume = 45.0