Given two integers **a** and **b** where **a** and **b** represents the length of adjacent sides of a parallelogram and an angle between them, the task is to find the length of diagonal of the parallelogram.**0**

**Examples:**

Input:a = 6, b = 10,~~0~~=30Output:6.14

Input:a = 3, b = 5,~~0~~=45Output:3.58

**Approach:** Consider a parallelogram **ABCD **with sides **a** and **b**, now apply cosine rule at angle **A **in the triangle **ABD **to find the length of diagonal **p**, similarly find diagonal **q **from triangle **ABC.**

Therefore the diagonals is given by:

## C++

`// C++ program to find length ` `// Of diagonal of a parallelogram ` `// Using sides and angle between them. ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` `#define PI 3.147 ` ` ` `// Function to return the length ` `// Of diagonal of a parallelogram ` `// using sides and angle between them. ` `double` `Length_Diagonal(` `int` `a, ` `int` `b, ` `double` `theta) ` `{ ` ` ` `double` `diagonal = ` `sqrt` `((` `pow` `(a, 2) + ` `pow` `(b, 2)) - ` ` ` `2 * a * b * ` `cos` `(theta * (PI / 180))); ` ` ` ` ` `return` `diagonal; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` ` ` `// Given sides ` ` ` `int` `a = 3; ` ` ` `int` `b = 5; ` ` ` ` ` `// Given angle ` ` ` `double` `theta = 45; ` ` ` ` ` `// Function call ` ` ` `double` `ans = Length_Diagonal(a, b, theta); ` ` ` ` ` `// Print the final answer ` ` ` `printf` `(` `"%.2f"` `, ans); ` `} ` ` ` `// This code is contributed by Amit Katiyar` |

*chevron_right*

*filter_none*

## Java

`// Java program to find length ` `// Of diagonal of a parallelogram ` `// Using sides and angle between them. ` `class` `GFG{ ` ` ` `// Function to return the length ` `// Of diagonal of a parallelogram ` `// using sides and angle between them. ` `static` `double` `Length_Diagonal(` `int` `a, ` `int` `b, ` ` ` `double` `theta) ` `{ ` ` ` `double` `diagonal = Math.sqrt((Math.pow(a, ` `2` `) + ` ` ` `Math.pow(b, ` `2` `)) - ` ` ` `2` `* a * b * ` ` ` `Math.cos(theta * ` ` ` `(Math.PI / ` `180` `))); ` ` ` ` ` `return` `diagonal; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` ` ` `// Given sides ` ` ` `int` `a = ` `3` `; ` ` ` `int` `b = ` `5` `; ` ` ` ` ` `// Given angle ` ` ` `double` `theta = ` `45` `; ` ` ` ` ` `// Function call ` ` ` `double` `ans = Length_Diagonal(a, b, theta); ` ` ` ` ` `// Print the final answer ` ` ` `System.out.printf(` `"%.2f"` `, ans); ` `} ` `} ` ` ` `// This code is contributed by amal kumar choubey ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 Program to find length ` `# Of diagonal of a parallelogram ` `# Using sides and angle between them. ` ` ` `import` `math ` ` ` `# Function to return the length ` `# Of diagonal of a parallelogram ` `# using sides and angle between them. ` `def` `Length_Diagonal(a, b, theta): ` ` ` ` ` `diagonal ` `=` `math.sqrt( ((a` `*` `*` `2` `) ` `+` `(b` `*` `*` `2` `)) ` ` ` `-` `2` `*` `a` `*` `b ` `*` `math.cos(math.radians(theta))) ` ` ` ` ` `return` `diagonal ` ` ` `# Driver Code ` ` ` `# Given Sides ` `a ` `=` `3` `b ` `=` `5` ` ` `# Given Angle ` `theta ` `=` `45` ` ` `# Function Call ` `ans ` `=` `Length_Diagonal(a, b, theta) ` ` ` `# Print the final answer ` `print` `(` `round` `(ans, ` `2` `)) ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find length ` `// Of diagonal of a parallelogram ` `// Using sides and angle between them. ` `using` `System; ` ` ` `class` `GFG{ ` ` ` `// Function to return the length ` `// Of diagonal of a parallelogram ` `// using sides and angle between them. ` `static` `double` `Length_Diagonal(` `int` `a, ` `int` `b, ` ` ` `double` `theta) ` `{ ` ` ` `double` `diagonal = Math.Sqrt((Math.Pow(a, 2) + ` ` ` `Math.Pow(b, 2)) - ` ` ` `2 * a * b * ` ` ` `Math.Cos(theta * ` ` ` `(Math.PI / 180))); ` ` ` ` ` `return` `diagonal; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` ` ` `// Given sides ` ` ` `int` `a = 3; ` ` ` `int` `b = 5; ` ` ` ` ` `// Given angle ` ` ` `double` `theta = 45; ` ` ` ` ` `// Function call ` ` ` `double` `ans = Length_Diagonal(a, b, theta); ` ` ` ` ` `// Print the readonly answer ` ` ` `Console.Write(` `"{0:F2}"` `, ans); ` `} ` `} ` ` ` `// This code is contributed by amal kumar choubey` |

*chevron_right*

*filter_none*

**Output:**

3.58

**Time Complexity:** O(1)**Auxiliary Space:** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Length of a Diagonal of a Parallelogram using the length of Sides and the other Diagonal
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Nth angle of a Polygon whose initial angle and per angle increment is given
- Find area of parallelogram if vectors of two adjacent sides are given
- Angle subtended by the chord when the angle subtended by another chord of same length is given
- Angle between a chord and a tangent when angle in the alternate segment is given
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given
- Find other two sides of a right angle triangle
- Length of remaining two sides of a Triangle from a given side and its adjacent angles
- Length of diagonals of a Rhombus using length of Side and vertex Angle
- Length of Diagonals of a Cyclic Quadrilateral using the length of Sides.
- Find the length of the median of a Triangle if length of sides are given
- Find area of triangle if two vectors of two adjacent sides are given
- Circumradius of a Cyclic Quadrilateral using the length of Sides
- Perimeter and Area of Varignon's Parallelogram
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
- Find the area of rhombus from given Angle and Side length

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.