Given the side of a square **a** which is kept inside a circle. It keeps expanding until all four of its vertices touch the circumference of the circle. Another smaller circle is kept inside the square now and it keeps expanding until its circumference touches all the four sides of the square. The outer and the inner circle form a ring. Find the area of this shaded part as shown in the image below.

**Examples:**

Input:a = 3

Output:7.06858

Input:a = 4

Output:12.566371

**Approach:**

From the above figure, **R = a / sqrt(2)** can be derived where **a** is the side length of the square. The area of the outer circle is **(pi * R * R)**.

Let **s1** be the area of the outer circle **(pi * R * R)** and **s2** be the area of the inner circle **(pi * r * r)**. Then the area of the ring is **s1 – s2**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the required area ` `float` `getArea(` `int` `a) ` `{ ` ` ` ` ` `// Calculate the area ` ` ` `float` `area = (M_PI * a * a) / 4.0; ` ` ` `return` `area; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `a = 3; ` ` ` ` ` `cout << getArea(a); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG { ` ` ` ` ` `// Function to return the required area ` ` ` `static` `float` `getArea(` `int` `a) ` ` ` `{ ` ` ` ` ` `// Calculate the area ` ` ` `float` `area = (` `float` `)(Math.PI * a * a) / ` `4` `; ` ` ` `return` `area; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `a = ` `3` `; ` ` ` `System.out.println(getArea(a)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python

`# Python3 implementation of the approach ` `import` `math ` ` ` `# Function to return the required area ` `def` `getArea(a): ` ` ` ` ` `# Calculate the area ` ` ` `area ` `=` `(math.pi ` `*` `a ` `*` `a) ` `/` `4` ` ` `return` `area ` ` ` `# Driver code ` `a ` `=` `3` `print` `(` `'{0:.6f}'` `.` `format` `(getArea(a))) ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to return the required area ` ` ` `static` `float` `getArea(` `int` `a) ` ` ` `{ ` ` ` ` ` `// Calculate the area ` ` ` `float` `area = (` `float` `)(Math.PI * a * a) / 4; ` ` ` `return` `area; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `a = 3; ` ` ` `Console.Write(getArea(a)); ` ` ` `} ` `} ` ` ` `// This code is contributed by mohit kumar 29 ` |

*chevron_right*

*filter_none*

**Output:**

7.06858

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 a square inscribed in a circle which is inscribed in an equilateral triangle
- Area of a square inscribed in a circle which is inscribed in a hexagon
- Area of a circle inscribed in a rectangle which is inscribed in a semicircle
- Program to calculate area of an Circle inscribed in a Square
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Radius of the biggest possible circle inscribed in rhombus which in turn is inscribed in a rectangle
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Area of the Largest square that can be inscribed in an ellipse
- Area of circle inscribed within rhombus
- Area of a circle inscribed in a regular hexagon
- Area of circle which is inscribed in equilateral triangle
- Area of decagon inscribed within the circle
- Find the area of largest circle inscribed in ellipse
- Area of largest Circle that can be inscribed in a SemiCircle
- Area of Equilateral triangle inscribed in a Circle of radius R
- Area of circle inscribed in a Isosceles Trapezoid

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.