Given the area of a square inscribed in a circle as N, the task is to calculate the area of a circle in which the square is inscribed.
Examples:
Input: N = 4
Output: 6.283
Input: N = 10
Output: 15.707
Approach:
Consider the below image:

- Let the area of the square is ‘A’
- The side of the square is given by = A**(1/2)
- A right-angled triangle is formed by the two sides of the square and the diameter of the circle
- The hypotenuse of the triangle will be the diameter of the circle
- The diameter of circle ‘D’ is calculated as ((A * A) + (A * A))**(1/2)
- The radius of circle ‘r’ is given by D/2
- The resultant area of the circle is pi*r*r
Below is the implementation of the above approach:
C++
#include <iostream>
#include<math.h>
#include <iomanip>
using namespace std;
double areaOfCircle( double a)
{
double pi=2* acos (0.0);
double side = pow (a,(1.0 / 2));
double D = pow ( ((side * side) + (side * side)) ,(1.0 / 2));
double R = D / 2;
double Area = pi * (R * R);
return Area;
}
int main() {
double areaOfSquare = 4;
cout<<setprecision(15)<<areaOfCircle(areaOfSquare);
return 0;
}
|
Java
import java.util.*;
class GFG
{
static double areaOfCircle( double a)
{
double side = Math.pow(a, ( 1.0 / 2 ));
double D = Math.pow(((side * side) + (side * side)),
( 1.0 / 2 ));
double R = D / 2 ;
double Area = Math.PI * (R * R);
return Area;
}
public static void main(String[] args)
{
double areaOfSquare = 4 ;
System.out.println(areaOfCircle(areaOfSquare));
}
}
|
Python3
import math
def areaOfCircle(a):
side = a * * ( 1 / 2 )
D = ((side * side) + (side * side)) * * ( 1 / 2 )
R = D / 2
Area = math.pi * (R * R)
return Area
areaOfSquare = 4
print (areaOfCircle(areaOfSquare))
|
C#
using System;
class GFG
{
static double areaOfCircle( double a)
{
double side = Math.Pow(a, (1.0 / 2));
double D = Math.Pow(((side * side) + (side * side)),
(1.0 / 2));
double R = D / 2;
double Area = Math.PI * (R * R);
return Area;
}
public static void Main()
{
double areaOfSquare = 4;
Console.Write(areaOfCircle(areaOfSquare));
}
}
|
Javascript
<script>
function areaOfCircle(a) {
let pi = 2 * Math.acos(0.0);
let side = Math.pow(a, (1.0 / 2));
let D = Math.pow(((side * side) + (side * side)), (1.0 / 2));
let R = D / 2;
let Area = Math.PI * (R * R);
return Area;
}
let areaOfSquare = 4;
document.write(areaOfCircle(areaOfSquare));
</script>
|
Time Complexity: O(1) as it would take constant time to perform operations
Auxiliary Space: O(1)