📜  求四边形的面积,当给定对角线和相对顶点的垂线时

📅  最后修改于: 2021-10-23 08:31:36             🧑  作者: Mango

给定三个整数dh1h2 ,其中d表示四边形对角线的长度。 h1h2表示从相对顶点到给定对角线的垂线的长度。任务是找到四边形的面积。

例子:

方法 :
四边形的面积是两个三角形的面积之和。我们知道三角形的面积是1/2*底*高。
因此,四边形的面积可以计算为:

下面是上述方法的实现:

C++
// C++ program to find the area of quadrilateral
#include 
using namespace std;
 
// Function to find the area of quadrilateral
float Area(int d, int h1, int h2)
{
    float area;
 
    area = 0.5 * d * (h1 + h2);
 
    return area;
}
 
// Driver code
int main()
{
    int d = 6, h1 = 4, h2 = 3;
 
    cout << "Area of Quadrilateral = " << (Area(d, h1, h2));
 
    return 0;
}


Java
// Java program to find the area of quadrilateral
class GFG
{
 
    // Function to find the area of quadrilateral
    static float Area(int d, int h1, int h2)
    {
        float area;
 
        area = (float) 0.5 * d * (h1 + h2);
 
        return area;
    }
 
    // Driver code
    public static void main(String[] args)
    {
        int d = 6, h1 = 4, h2 = 3;
 
        System.out.println("Area of Quadrilateral = " +
                                      Area(d, h1, h2));
    }
}
 
// This code is contributed by Princi Singh


Python3
# Python3 program to find
# the area of quadrilateral
 
# Function to find the
# area of quadrilateral
def Area(d, h1, h2):
 
    area = 0.5 * d * (h1 + h2);
 
    return area;
 
# Driver code
if __name__ == '__main__':
     
    d = 6;
    h1 = 4;
    h2 = 3;
 
    print("Area of Quadrilateral = ",
                  (Area(d, h1, h2)));
 
# This code is contributed by Rajput-Ji


C#
// C# program to find the area of quadrilateral
using System;
 
class GFG
{
     
// Function to find the area of quadrilateral
static float Area(int d, int h1, int h2)
{
    float area;
 
    area = (float)0.5 * d * (h1 + h2);
 
    return area;
}
 
 
// Driver code
public static void Main()
{
    int d = 6, h1 = 4, h2 = 3;
     
    Console.WriteLine("Area of Quadrilateral = " +
                                 Area(d, h1, h2));
}
}
 
// This code is contributed by nidhiva


Javascript


输出:
Area of Quadrilateral = 21

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程