Open In App

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

Last Updated : 07 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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++




// 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 rhombus
double 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 code
int main()
{
    double d = 7.07;
    double a = 5;
    printf("%0.8f", area(d, a));
}
 
// This code is contributed by Mohit Kumar


Java




// Java program to calculate the area of a rhombus
// whose one side and one diagonal is given
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;
        System.out.println(area(d, a));
    }
}
 
// This code is contributed by AnkitRai01


Python3




# Python program to calculate
# the area of a rhombus
# whose one side and
# one diagonal is given
 
# function to calculate
# the area of the rhombus
def 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 code
d = 7.07
a = 5
print(area(d, a))


C#




// C# program to calculate the area of a rhombus
// whose one side and one diagonal is given
using 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


Javascript




<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 rhombus
function 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 code
var d = 7.07;
var a = 5;
document.write(area(d, a));
 
// This code is contributed by 29AjayKumar
</script>


Output: 

24.999998859949972

 

Time Complexity: O(log(n)) as inbuilt sqrt function is used

Auxiliary Space: O(1)



Similar Reads

Program to calculate area and perimeter of a rhombus whose diagonals are given
Given the length of diagonals of a rhombus, d1 and d2. The task is to find the perimeter and 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: d1 = 2 and d2 = 4 Output: The area of rhombus with diagonals 2 and 4 is 4. The perimeter of
5 min read
Find the area of rhombus from given Angle and Side length
Given two integers A and X, denoting the length of a side of a rhombus and an angle respectively, the task is to find the area of the rhombus. A rhombus is a quadrilateral having 4 sides of equal length, in which both the opposite sides are parallel, and opposite angles are equal. Examples: Input: A = 4, X = 60Output: 13.86 Input: A = 4, X = 30Outp
3 min read
Area of a Square | Using Side, Diagonal and Perimeter
Given one of the Sides S, Diagonal D, or Perimeter P of the square, the task is to find the area of the square with the given value. Examples: Input: S = 5 Output: Area of the square using side = 25 Input: D = 4 Output: Area of the square using diagonal = 8 Input: P = 32 Output: Area of the square using perimeter = 64 Finding Area of Square using i
7 min read
Length of diagonals of a Rhombus using length of Side and vertex Angle
Given two integers A and theta, denoting the length of a side of a rhombus and the vertex angle respectively, the task is to find the length of the diagonals of the rhombus. Examples: Input: A = 10, theta = 30 Output: 19.32 5.18 Input: A = 6, theta = 45 Output: 11.09 4.59 Approach: The problem can be solved using the law of cosines. Using the law o
4 min read
Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
Given two integers A, B representing the length of two sides of a triangle and an integer K representing the angle between them in radian, the task is to calculate the area of the triangle from the given information.Examples: Input: a = 9, b = 12, K = 2 Output: 49.1 Explanation: Area of triangle = 1 / 2 * (9 * 12 * Sin 2) = 35.12Input: A = 2, B = 4
4 min read
Calculate area of pentagon with given diagonal
Given an integer d which is the length of the diagonal of a pentagon, the task is to find the area of that pentagon. Examples: Input: d = 5 Output: 16.4291Input: d = 10 Output: 65.7164 Approach: Pentagon is a regular polygon having five equal sides and all equal angles. The interior angles of pentagon are of 108 degrees each and the sum of all angl
3 min read
Calculate area of a cyclic quadrilateral with given side lengths
Given four positive integers A, B, C, and D representing the length of sides of a Cyclic Quadrilateral, the task is to find the area of the Cyclic Quadrilateral. Examples: Input: A = 10, B = 15, C = 20, D = 25Output: 273.861 Input: A = 10, B = 30, C = 50, D = 20Output: 443.706 Approach: The given problem can be solved based on the following observa
5 min read
Program to swap upper diagonal elements with lower diagonal elements of matrix.
Given a square matrix, swap upper diagonal elements of matrix with lower diagonal elements of matrix. Examples : Input: 2 3 5 6 4 5 7 9 8 6 4 9 1 3 5 6 Output: 2 4 8 1 3 5 6 3 5 7 4 5 6 9 9 6 Input: 1 2 3 4 5 6 7 8 9 Output: 1 4 7 2 5 8 3 6 9Recommended PracticeSwapping TrianglesTry It! Below is the implementation of above idea : C/C++ Code // CPP
7 min read
Maximum sum of elements in a diagonal parallel to the main diagonal of a given Matrix
Give a square matrix mat[][] of dimensions N * N, the task is to find the maximum sum of elements present in the given matrix along the diagonals which are parallel to the main diagonal. Below is the image of the same. Examples: Input: mat[][] = {{1, 2, 5, 7}, {2, 6, 7, 3}, {12, 3, 2, 4}, {3, 6, 9, 4}}Output: 18Explanation:Sum of elements present i
11 min read
Area of the biggest possible rhombus that can be inscribed in a rectangle
Given a rectangle of length l and breadth b, the task is to find the largest rhombus that can be inscribed in the rectangle.Examples: Input : l = 5, b = 4 Output : 10 Input : l = 16, b = 6 Output : 48 From the figure, we can see, the biggest rhombus that could be inscribed within the rectangle will have its diagonals equal to the length &amp; bread
4 min read