Open In App

C++ Program to Find Diagonal of a Rectangle

Last Updated : 15 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Given two positive integers i.e, the length and breadth of the rectangle, the task is to find the length of the Diagonal of a Rectangle.

Diagonal of a Rectangle

 

Example:

Input: length=4 breadth=3

output: The Diagonal is 5

The diagonal of a rectangle is sqrt (a*a+ b*b)

C++




// C++ Program to Find Diagonal of a Rectangle
#include <bits/stdc++.h>
  
using namespace std;
  
// Function to find the length of the
// diagonal of a rectangle of given sides
double findDiagonal(double a, double b)
{
    return sqrt(a * a + b * b);
}
  
// Driver Code
int main()
{
    double a = 4, b = 3; // a is the length and b is the
                         // breadth of the rectangle
    cout << "The Diagonal is " << findDiagonal(a, b);
  
    return 0;
}


Output

The Diagonal is 5

Time Complexity: O(1)

Auxiliary Space: O(1)


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads