Program to calculate the length of the diagonal in a rectangle Last Updated : 18 Jan, 2024 Comments Improve Suggest changes Like Article Like Report Write a program to calculate the length of the diagonal in a rectangle with the given length and breadth. Examples: Input: Length = 5, Width = 3Output: Diagonal Length = 5.83095 Input: Length = 8, Width = 6Output: 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: Square the length and width.Sum the squares.Take the square root of the sum.Below is the implementation of the algorithm: C++ #include <cmath> #include <iostream> using namespace std; int main() { double L = 5, W = 3; double diagonal = sqrt(L * L + W * W); cout << "Diagonal Length: " << diagonal << endl; return 0; } C #include <math.h> #include <stdio.h> int main() { double L = 5, W = 3; double diagonal = sqrt(L * L + W * W); printf("Diagonal Length: %lf\n", diagonal); return 0; } Java public class DiagonalLength { public static void main(String[] args) { double L = 5, W = 3; double diagonal = Math.sqrt(Math.pow(L, 2) + Math.pow(W, 2)); System.out.println("Diagonal Length: " + diagonal); } } Python3 import math L, W = 5, 3 diagonal = math.sqrt(L**2 + W**2) print(f"Diagonal Length: {diagonal}") C# using System; class Program { static void Main() { double L = 5, W = 3; double diagonal = Math.Sqrt(Math.Pow(L, 2) + Math.Pow(W, 2)); Console.WriteLine("Diagonal Length: " + diagonal); } } JavaScript let L = 5, W = 3; let diagonal = Math.sqrt(L ** 2 + W ** 2); console.log("Diagonal Length: " + diagonal); OutputDiagonal Length: 5.83095 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to calculate the length of the diagonal in a rectangle C code_r Follow Improve Article Tags : DSA Similar Reads Program to calculate length of diagonal of a square Given a positive integer S, the task is to find the length of diagonal of a square having sides of length S. Examples: Input: S = 10Output: 14.1421Explanation: The length of the diagonal of a square whose sides are of length 10 is 14.1421 Input: S = 24Output: 33.9411 Approach: The given problem can 3 min read Length and Breadth of rectangle such that ratio of Area to diagonal^2 is maximum Given an array of positive integers. The task is to choose a pair of elements from the given array such that they represent the length and breadth of a rectangle and the ratio of its area and its diagonal2 is maximum. Note: The array must contains all sides of the rectangle. That is you can choose e 7 min read Program to check if a rectangle is a square or not Given the dimensions of a rectangle (length and breadth), write a program to determine whether the given rectangle is a square or not.Examples:Input: Length = 5, Breadth = 5 Output: SquareExplanation: Since the length and breadth of the rectangle is same, therefore the given rectangle is a square.In 2 min read Program to find the side length of a square given its area Write a program to find the side length of a square with given area. Examples: Input: Area = 16 square units Output: Side length = 4 units Input: Area = 25 square meters Output: Side length = 5 meters Approach: To solve the problem, follow the below idea: The side length of a square can be calculate 2 min read Program to calculate the area of Kite Kite is something like rhombus but in Kite, the adjacent sides are equal and diagonals are generally not equal. Method 1: When both the diagonals are givenIf diagonals d1 and d2 are given of the kite, then the area of a kite is half of product of both the diagonals i.e. \ Area = \frac{ d1 * d2 } {2} 5 min read Like