![]() |
VOOZH | about |
Write a program to calculate the length of the diagonal in a rectangle with the given length and breadth.
Examples:
Input: Length = 5, Width = 3
Output: Diagonal Length = 5.83095Input: Length = 8, Width = 6
Output: Diagonal Length = 10
Approach: To solve the problem, follow the below idea:
The diagonal of a rectangle forms a right-angled triangle with the length and width of the rectangle. We can use the Pythagoras theorem to calculate the length of the diagonal. So, we can use this formula Diagonal2 = Length2 + Breadth2 to calculate the length of the diagonal.
Step-by-step algorithm:
Below is the implementation of the algorithm:
Diagonal Length: 5.83095
Time Complexity: O(1)
Auxiliary Space: O(1)