Program to calculate area of a rhombus whose one side and diagonal are given

19 Mar, 2022
Given the length of diagonal ‘d1’ of a rhombus and a side ‘a’, the task is to find the area of that rhombus. 
A rhombus is a polygon having 4 equal sides in which both the opposite sides are parallel, and opposite angles are equal.
 
Examples:  
Input: d = 15, a = 10
Output: 99.21567416492215

Input: d = 20, a = 18
Output: 299.3325909419153
 
Approach: 
Get the diagonal ‘d1’ and side ‘a’ of the rhombus
We know that,  
 
But since we don’t know the other diagonal d2, we cannot use this formula yet
So we first find the second diagonal d2 with the help of d1 and a 
 
Now we can use the area formula to compute the area of the Rhombus
 
C++
Java
Python3
C#
Javascript
// C++ program to calculate the area of a rhombus// whose one side and one diagonal is given#include<bits/stdc++.h>using namespace std; // function to calculate the area of the rhombusdouble area(double d1, double a){         // Second diagonal    double d2 = sqrt(4 * (a * a) - d1 * d1);     // area of rhombus    double area = 0.5 * d1 * d2;     // return the area    return area;} // Driver codeint main(){    double d = 7.07;    double a = 5;    printf("%0.8f", area(d, a));} // This code is contributed by Mohit Kumar
// Java program to calculate the area of a rhombus// whose one side and one diagonal is givenclass GFG{     // function to calculate the area of the rhombus    static double area(double d1, double a)    {                 // Second diagonal        double d2 = Math.sqrt(4 * (a * a) - d1 * d1);             // area of rhombus        double area = 0.5 * d1 * d2;             // return the area        return area;    }         // Driver code    public static void main (String[] args)    {        double d = 7.07;        double a = 5;        System.out.println(area(d, a));    }} // This code is contributed by AnkitRai01
# Python program to calculate# the area of a rhombus# whose one side and# one diagonal is given # function to calculate# the area of the rhombusdef area(d1, a):         # Second diagonal    d2 = (4*(a**2) - d1**2)**0.5         # area of rhombus    area = 0.5 * d1 * d2         # return the area    return(area) # driver coded = 7.07a = 5print(area(d, a))
// C# program to calculate the area of a rhombus// whose one side and one diagonal is givenusing System; class GFG{     // function to calculate the area of the rhombus    static double area(double d1, double a)    {                 // Second diagonal        double d2 = Math.Sqrt(4 * (a * a) - d1 * d1);             // area of rhombus        double area = 0.5 * d1 * d2;             // return the area        return area;    }         // Driver code    public static void Main (String []args)    {        double d = 7.07;        double a = 5;        Console.WriteLine(area(d, a));    }} // This code is contributed by Arnab Kundu
<script>// javascript program to calculate the area of a rhombus// whose one side and one diagonal is given  // function to calculate the area of the rhombusfunction area(d1 , a){         // Second diagonal    var d2 = Math.sqrt(4 * (a * a) - d1 * d1);     // area of rhombus    var area = 0.5 * d1 * d2;     // return the area    return area;} // Driver codevar d = 7.07;var a = 5;document.write(area(d, a)); // This code is contributed by 29AjayKumar</script>
24.999998859949972
 
Time Complexity: O(1)
Auxiliary Space: O(1)
mohit kumar 29
ankthon
andrew1234
29AjayKumar
subham348
area-volume-programs
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.