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 = 60
Output: 13.86Input: A = 4, X = 30
Output: 8.0
Approach:For a Rhombus ABCD having the length of a side a and an angle x, the area of triangle ABD can be calculated using Side-Angle-Side property of triangle by the following equation:
Area of Triangle ABD = 1/2 (a2) sin x
Area of Rhombus ABCD will be double the area of ABD triangle.Therefore, Area of Rhombus ABCD = (a2) sin x
Below is the implementation of the above approach:
C++
// C++ Program to calculate// area of rhombus from given// angle and side length#include <bits/stdc++.h>using namespace std;Â
#define RADIAN 0.01745329252// Function to return the area of rhombus// using one angle and side.float Area_of_Rhombus(int a, int theta){Â Â Â Â float area = (a * a) * sin((RADIAN * theta));Â Â Â Â return area;}Â
// Driver Codeint main(){Â Â Â Â int a = 4;Â Â Â Â int theta = 60;Â
    // Function Call    float ans = Area_of_Rhombus(a, theta);Â
    // Print the final answer    printf("%0.2f", ans);    return 0;}Â
// This code is contributed by Rajput-Ji |
Java
// Java Program to calculate// area of rhombus from given// angle and side lengthclass GFG{Â
static final double RADIAN = 0.01745329252;Â Â Â // Function to return the area of rhombus// using one angle and side.static double Area_of_Rhombus(int a, int theta){Â Â Â Â double area = (a * a) * Math.sin((RADIAN * theta));Â Â Â Â return area;}Â
// Driver Codepublic static void main(String[] args){Â Â Â Â int a = 4;Â Â Â Â int theta = 60;Â
    // Function Call    double ans = Area_of_Rhombus(a, theta);Â
    // Print the final answer    System.out.printf("%.2f", ans);}}Â
// This code is contributed by Rajput-Ji |
Python3
# Python3 Program to calculate # area of rhombus from given # angle and side length   import math    # Function to return the area of rhombus # using one angle and side. def Area_of_Rhombus(a, theta):        area = (a**2) * math.sin(math.radians(theta))       return area    # Driver Code a = 4theta = 60   # Function Call ans = Area_of_Rhombus(a, theta)    # Print the final answerprint(round(ans, 2)) |
C#
// C# Program to calculate// area of rhombus from given// angle and side lengthusing System;class GFG{Â
static readonly double RADIAN = 0.01745329252;Â Â Â // Function to return the area of rhombus// using one angle and side.static double Area_of_Rhombus(int a, int theta){Â Â Â Â double area = (a * a) * Math.Sin((RADIAN * theta));Â Â Â Â return area;}Â
// Driver Codepublic static void Main(String[] args){Â Â Â Â int a = 4;Â Â Â Â int theta = 60;Â
    // Function Call    double ans = Area_of_Rhombus(a, theta);Â
    // Print the readonly answer    Console.Write("{0:F2}", ans);}}Â
// This code is contributed by Rajput-Ji |
Javascript
<script>Â
// Javascript Program to calculate// area of rhombus from given// angle and side length        // Function to return the area of rhombus// using one angle and side. function Area_of_Rhombus(a, theta){        var area = (a**2) * Math.sin(theta *Math.PI/180);        return area ;}    // Driver Code a = 4theta = 60    // Function Call ans = Area_of_Rhombus(a, theta)      // Print the final answerdocument.write(Math.round(ans * 100) / 100);Â
</script> |
13.86
Â
Time Complexity: O(1)
Auxiliary Space: O(1)
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!




