Find the area of quadrilateral when diagonal and the perpendiculars to it from opposite vertices are given

08 Jul, 2022
Given three integers d, h1, h2 where d represents the length of the diagonal of a quadrilateral. h1 and h2 represents the lengths of the perpendiculars to the given diagonal from the opposite vertices. The task is to find the area of the Quadrilateral. 
Examples:  
Input : d= 6, h1 = 4, h2 = 3 Output : 21Input : d= 10, h1 = 8, h2 = 10 Output : 90  
 
Approach : Area of the quadrilateral is the sum of the areas of both triangles. We know that the area of the triangle is 1/2*base*height.Therefore, the area of a quadrilateral can be calculated as :  
Area = 1/2 * d * h1 + 1/2 * d * h2 = 1/2 * d * ( h1 + h2 )  
Below is the implementation of the above approach :  
C++
Java
Python3
C#
Javascript
// C++ program to find the area of quadrilateral#include <bits/stdc++.h>using namespace std; // Function to find the area of quadrilateralfloat Area(int d, int h1, int h2){    float area;     area = 0.5 * d * (h1 + h2);     return area;} // Driver codeint main(){    int d = 6, h1 = 4, h2 = 3;     cout << "Area of Quadrilateral = " << (Area(d, h1, h2));     return 0;}
// Java program to find the area of quadrilateralclass 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 program to find# the area of quadrilateral # Function to find the# area of quadrilateraldef Area(d, h1, h2):     area = 0.5 * d * (h1 + h2);     return area; # Driver codeif __name__ == '__main__':         d = 6;    h1 = 4;    h2 = 3;     print("Area of Quadrilateral = ",                  (Area(d, h1, h2))); # This code is contributed by Rajput-Ji
// C# program to find the area of quadrilateralusing System; class GFG{     // Function to find the area of quadrilateralstatic float Area(int d, int h1, int h2){    float area;     area = (float)0.5 * d * (h1 + h2);     return area;}  // Driver codepublic 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
<script> // JavaScript program to find the area of quadrilateral // Function to find the area of quadrilateralfunction Area(d, h1, h2){    let area;     area = 0.5 * d * (h1 + h2);     return area;} // Driver code     let d = 6, h1 = 4, h2 = 3;     document.write("Area of Quadrilateral = " + (Area(d, h1, h2)));  // This code is contributed by Surbhi Tyagi. </script>
Area of Quadrilateral = 21
 
Time Complexity: O(1)Auxiliary Space: O(1)
nidhiva
princi singh
Rajput-Ji
Akanksha_Rai
surbhityagi15
singhh3010
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Rotation of a point about another point in C++
Maximum Manhattan distance between a distinct pair from N coordinates
C++ Program to Illustrate Trigonometric functions
Total area of two overlapping rectangles
Largest area possible after removal of a series of horizontal & vertical bars
Program for Fibonacci numbers
Set in C++ Standard Template Library (STL)
Write a program to print all permutations of a given string
C++ Data Types
Merge two sorted arrays