Area of largest semicircle that can be drawn inside a square
Last Updated :
21 Jun, 2022
Given a square of side a, the task is to find the area of the largest semi-circle that can be drawn inside the square.
Examples:
Input: a = 3
Output: 4.84865
Input: a = 4
Output: 8.61982
Approach
The semicircle of maximal area inscribed in the square has its diameter parallel to a diagonal, and its radius rmax is given as:
- Since the figure is symmetrical in the diagonal BD, angle QPB = 45°.
OY = r cos 45 = r/ ?2
a = AB
= r + r/?2
= r(1 + 1/?2)
r = a / (1 + 1/?2)
= a*?2 / (?2 + 1)
- Rationalizing the denominator, we obtain
r = a*?2*(?2-1)
r = a*2 - a ?2
= a*(2-?2)
Area of the required semicircle
= pi * r2/2
= 3.14*(a*(2-?2))2 / 2
- Below is the implementation of the above approach:
CPP
#include <bits/stdc++.h>
using namespace std;
float find_Area( float a)
{
float R = a * (2.0 - sqrt (2));
float area = 3.14 * R * R / 2.0;
return area;
}
int main()
{
float a = 4;
cout << " Area of semicircle = "
<< find_Area(a);
return 0;
}
|
Java
class GFG {
static float find_Area( float a)
{
float R = a * ( float )( 2.0 - Math.sqrt( 2 ));
float area = ( float )(( 3.14 * R * R) / 2.0 );
return area;
}
public static void main (String[] args)
{
float a = 4 ;
System.out.println( " Area of semicircle = " + find_Area(a));
}
}
|
Python3
from math import sqrt
def find_Area(a) :
R = a * ( 2.0 - sqrt( 2 ));
area = 3.14 * R * R / 2.0 ;
return area;
if __name__ = = "__main__" :
a = 4 ;
print ( "Area of semicircle =" ,find_Area(a));
|
C#
using System;
class GFG {
static float find_Area( float a)
{
float R = a * ( float )(2.0 - Math.Sqrt(2));
float area = ( float )((3.14 * R * R) / 2.0);
return area;
}
public static void Main ( string [] args)
{
float a = 4;
Console.WriteLine( " Area of semicircle = " + find_Area(a));
}
}
|
Javascript
<script>
function find_Area(a)
{
var R = a * (2.0 - Math.sqrt(2));
var area = 3.14 * R * R / 2.0;
return area;
}
var a = 4;
document.write( " Area of semicircle = "
+ find_Area(a));
</script>
|
Output:
Area of semicircle = 8.61982
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...