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
- Hence
a = AB = r + r/√2 = r(1 + 1/√2)
- Thus
r = a / (1 + 1/√2) = a*√2 / (√2 + 1)
- Rationalizing the denominator, we obtain
r = a*√2*(√2-1)
- Thus
r = a*2 - a √2 = a*(2-√2)
- Therfore,
Area of the required semicircle = pi * r2/2 = 3.14*(a*(2-√2))2 / 2
Below is the implementation of the above approach:
CPP
// C++ program to find Area of// semicircle in a square#include <bits/stdc++.h>usingnamespacestd;// Function to find area of semicirclefloatfind_Area(floata){floatR = a * (2.0 -sqrt(2));floatarea = 3.14 * R * R / 2.0;returnarea;}// Driver codeintmain(){// side of a squarefloata = 4;// Call Function to find// the area of semicirclecout <<" Area of semicircle = "<< find_Area(a);return0;}chevron_rightfilter_noneJava
// Java program to find Area of// semicircle in a squareclassGFG {// Function to find area of semicirclestaticfloatfind_Area(floata){floatR = a * (float)(2.0- Math.sqrt(2));floatarea = (float)((3.14* R * R) /2.0);returnarea;}// Driver codepublicstaticvoidmain (String[] args){// side of a squarefloata =4;// Call Function to find// the area of semicircleSystem.out.println(" Area of semicircle = "+ find_Area(a));}}// This code is contributed by AnkitRai01chevron_rightfilter_nonePython3
# Python3 program to find Area of# semicircle in a squarefrommathimportsqrt# Function to find area of semicircledeffind_Area(a) :R=a*(2.0-sqrt(2));area=3.14*R*R/2.0;returnarea;# Driver codeif__name__=="__main__":# side of a squarea=4;# Call Function to find# the area of semicircleprint("Area of semicircle =",find_Area(a));# This code is contributed by AnkitRai01chevron_rightfilter_noneC#
// C# program to find Area of// semicircle in a squareusingSystem;classGFG {// Function to find area of semicirclestaticfloatfind_Area(floata){floatR = a * (float)(2.0 - Math.Sqrt(2));floatarea = (float)((3.14 * R * R) / 2.0);returnarea;}// Driver codepublicstaticvoidMain (string[] args){// side of a squarefloata = 4;// Call Function to find// the area of semicircleConsole.WriteLine(" Area of semicircle = "+ find_Area(a));}}// This code is contributed by AnkitRai01chevron_rightfilter_noneOutput:Area of semicircle = 8.61982
Reference: http://www.qbyte.org/puzzles/p153s.html
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Area of largest Circle that can be inscribed in a SemiCircle
- Largest square that can be inscribed in a semicircle
- Largest rectangle that can be inscribed in a semicircle
- Largest triangle that can be inscribed in a semicircle
- Largest trapezoid that can be inscribed in a semicircle
- Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
- Area of a circle inscribed in a rectangle which is inscribed in a semicircle
- Program to find the Area and Perimeter of a Semicircle
- Biggest Reuleaux Triangle inscirbed within a square inscribed in a semicircle
- Count of squares that can be drawn without lifting the pencil
- Count of nested polygons that can be drawn by joining vertices internally
- Sum of Area of all possible square inside a rectangle
- Area of a leaf inside a square
- Find side of Square which makes minimal area to fit two identical rectangles inside it
- Area of the Largest square that can be inscribed in an ellipse
- Largest area square in an array when elements can be shuffled
- Largest sphere that can be inscribed inside a cube
- Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points
- Area of a largest square fit in a right angle triangle
- Maximize a value for a semicircle of given radius
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AnkitRai01


