Circumradius of the rectangle
Last Updated :
23 Jul, 2022
Here we have a rectangle of length l & breadth b. We have to find the circumradius of the rectangle.
Examples:
Input : l = 3, b = 4
Output :2.5
Input :l = 10, b = 12
Output :3.95227774224
Approach:
From the diagram, we can clearly understand the circumradius r is half of the diagonal of the rectangle.
r = ?(l^2 + b^2)/2
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float findRadiusOfcircumcircle( float l, float b)
{
if (l < 0 || b < 0)
return -1;
float radius = sqrt ( pow (l, 2) + pow (b, 2)) / 2;
return radius;
}
int main()
{
float l = 4, b = 3;
cout << findRadiusOfcircumcircle(l, b) << endl;
return 0;
}
|
C
#include <stdio.h>
#include <math.h>
float findRadiusOfcircumcircle( float l, float b)
{
if (l < 0 || b < 0)
return -1;
float radius = sqrt ( pow (l, 2) + pow (b, 2)) / 2;
return radius;
}
int main()
{
float l = 4, b = 3;
printf ( "%f\n" ,findRadiusOfcircumcircle(l, b));
return 0;
}
|
Java
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
{
static float findRadiusOfcircumcircle( float l,
float b)
{
if (l < 0 || b < 0 )
return - 1 ;
float radius = ( float ) Math.sqrt(Math.pow(l, 2 ) +
Math.pow(b, 2 )) / 2 ;
return radius;
}
public static void main(String args[])
{
float l = 4 , b = 3 ;
System.out.println(findRadiusOfcircumcircle(l, b));
}
}
|
Python3
import math
def findRadiusOfcircumcircle(l, b):
if (l < 0 or b < 0 ):
return - 1 ;
radius = (math.sqrt( pow (l, 2 ) +
pow (b, 2 )) / 2 );
return radius;
l = 4 ;
b = 3 ;
print (findRadiusOfcircumcircle(l, b));
|
C#
using System;
class GFG
{
static float findRadiusOfcircumcircle( float l,
float b)
{
if (l < 0 || b < 0)
return -1;
float radius = ( float ) Math.Sqrt(Math.Pow(l, 2) +
Math.Pow(b, 2)) / 2;
return radius;
}
public static void Main()
{
float l = 4, b = 3;
Console.WriteLine(findRadiusOfcircumcircle(l, b));
}
}
|
PHP
<?php
function findRadiusOfcircumcircle( $l , $b )
{
if ( $l < 0 || $b < 0)
return -1;
$radius = sqrt(pow( $l , 2) +
pow( $b , 2)) / 2;
return $radius ;
}
$l = 4; $b = 3;
echo findRadiusOfcircumcircle( $l , $b );
?>
|
Javascript
<script>
function findRadiusOfcircumcircle(l,b)
{
if (l < 0 || b < 0)
return -1;
var radius = Math.sqrt(Math.pow(l, 2) +
Math.pow(b, 2)) / 2;
return radius;
}
var l = 4, b = 3;
document.write(findRadiusOfcircumcircle(l, b).toFixed(6));
</script>
|
Output:
2.5
Time Complexity: O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...