Given the side of a square. The task is to find the area of an inscribed circle in a square.
Examples:
Input : a = 8
Output : Area of an inscribed circle: 50.24
Input : a = 12.04
Output : Area of an inscribed circle: 113.795
Given a square i.e. all sides of a square are of equal length and all four angles are 90 degrees. Below diagram depicts an inscribed circle in a square.

Properties of an inscribed circle in a square:
- The diameter of an inscribed circle in a square is equal to the length of the side of a square.
- With at least one measure of the circle or the square, the area and the perimeter of the square can be calculated in which the circle is inscribed.
- The center of the square and the center of the circle lie at a same point.
- when at least one measure of the circle or the square is given, the circumference and area of the circle can be calculated.
Formula to find the area of an inscribed circle:? /{4} a2
where a is the side of a square in which a circle is inscribed.
How does the formula works?
Assume a is the side of a square and we know that a square has 4 sides.
Area of a circle = ? r2
where r is the radius of a circle and area of a square = a2
Therefore, the area of an inscribed circle in a square = ? r2
Now, put r = a / 2
So, the area of an inscribed circle in a square ? /{4} a2
C++
#include<bits/stdc++.h>
#define PI 3.14
using namespace std;
float areaOfInscribedCircle( float a)
{
return ( PI / 4 ) * a * a;
}
int main()
{
float a = 8;
cout << "Area of an inscribed circle: "
<< areaOfInscribedCircle(a);
return 0;
}
|
Java
import java.io.*;
class GFG {
static double PI = 3.14 ;
static double areaOfInscribedCircle( float a)
{
return ( PI / 4 ) * a * a;
}
public static void main (String[] args)
{
float a = 8 ;
System.out.println( "Area of an inscribed"
+ " circle: " + areaOfInscribedCircle(a));
}
}
|
Python3
PI = 3.14
def areaOfInscribedCircle(a):
return ( PI / 4 ) * a * a
a = 8
print ( "Area of an inscribed circle:" ,
round (areaOfInscribedCircle(a), 2 ))
|
C#
using System;
class GFG
{
static double PI = 3.14;
static double areaOfInscribedCircle( float a)
{
return (PI / 4 ) * a * a;
}
public static void Main ()
{
float a = 8;
Console.WriteLine( "Area of an inscribed" +
" circle: " +
areaOfInscribedCircle(a));
}
}
|
PHP
<?php
$PI = 3.14;
function areaOfInscribedCircle( $a )
{
global $PI ;
return ( $PI / 4 ) *
$a * $a ;
}
$a = 8;
echo "Area of an inscribed circle: " ,
areaOfInscribedCircle( $a );
?>
|
Javascript
<script>
var PI =3.14;
function areaOfInscribedCircle(a)
{
return ( PI / 4 ) * a * a;
}
var a = 8;
document.write( "Area of an inscribed circle: "
+ areaOfInscribedCircle(a));
</script>
|
Output
Area of an inscribed circle: 50.24
Time Complexity: O(1)
Auxiliary Space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!
Last Updated :
09 Jun, 2022
Like Article
Save Article