Find the area of the shaded region formed by the intersection of four semicircles in a square
Given the length of the side of a square a, the task is to find the area of the shaded region formed by the intersection of four semicircles in a square as shown in the image below:
Examples:
Input: a = 10
Output: 57
Input: a = 19
Output: 205.77
Approach: Area of the shaded region will be:
Area(semicircle1) + Area(semicircle2) + Area(semicircle3) + Area(semicircle4) – Area(square).
Since all semicircles are of same radius, therefore, area of all semicircles will be equal. So, the above formula can be written as:
4*(Area of Semicircle) – Area(Square)
The area of a semicircle is (3.14 * r2) / 2 where r is the radius of the semicircle which is equal to a / 2.
Hence, Area of the shaded region = 4 * (3.14 * (a * a) / 8 ) – a * a
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float findAreaShaded( float a)
{
float sqArea = a * a;
float semiCircleArea = (3.14 * (a * a) / 8);
float ShadedArea = 4 * semiCircleArea - sqArea;
return ShadedArea;
}
int main()
{
float a = 10;
cout << findAreaShaded(a);
return 0;
}
|
Java
class GFG {
static float findAreaShaded( float a)
{
float sqArea = a * a;
float semiCircleArea = ( float )( 3.14 * (a * a) / 8 );
float ShadedArea = 4 * semiCircleArea - sqArea;
return ShadedArea;
}
public static void main(String[] args)
{
float a = 10 ;
System.out.println(findAreaShaded(a));
}
}
|
Python3
def findAreaShaded(a):
sqArea = a * a;
semiCircleArea = ( 3.14 * (a * a ) / 8 )
ShadedArea = 4 * semiCircleArea - sqArea ;
return ShadedArea;
if __name__ = = '__main__' :
a = 10
print (findAreaShaded(a))
|
C#
using System;
class GFG
{
static float findAreaShaded( float a)
{
float sqArea = a * a;
float semiCircleArea = ( float )(3.14 * (a * a) / 8);
float ShadedArea = 4 * semiCircleArea - sqArea;
return ShadedArea;
}
public static void Main()
{
float a = 10;
Console.WriteLine(findAreaShaded(a));
}
}
|
PHP
<?php
function findAreaShaded( $a )
{
$sqArea = $a * $a ;
$semiCircleArea = (3.14 * ( $a * $a ) / 8);
$ShadedArea = 4 * $semiCircleArea - $sqArea ;
return $ShadedArea ;
}
$a = 10;
echo findAreaShaded( $a );
?>
|
Javascript
<script>
function findAreaShaded( a)
{
let sqArea = a * a;
let semiCircleArea = (3.14 * (a * a) / 8);
let ShadedArea = 4 * semiCircleArea - sqArea;
return ShadedArea;
}
let a = 10;
document.write(findAreaShaded(a));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
09 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...