Find area of the Circle when the area of inscribed Square is given - GeeksforGeeks

24 Nov, 2021
Given area of square inscribed in a circle as N, the task is to calculate the area of circle in which the square is inscribed.
Examples: 
Input: N = 4 Output: 6.283
Input: N = 10Output:  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 triangle will be diameter of 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++
Java
Python3
C#
Javascript
#include <iostream>#include<math.h>#include <iomanip>using namespace std; // Function to calculate the area of circledouble areaOfCircle(double a){    // declaring pi    double pi=2*acos(0.0);           // Side of the square    double side = pow(a,(1.0 / 2));     // Diameter of circle    double D =pow( ((side * side) + (side * side)) ,(1.0 / 2));     // Radius of circle    double R = D / 2;     // Area of circle    double Area = pi * (R * R);     return Area; } //Driver Codeint main() {        double areaOfSquare = 4;    cout<<setprecision(15)<<areaOfCircle(areaOfSquare);    return 0;}// This code is contributed by ANKITKUMAR34
// Java code for the above approachimport java.util.*; class GFG{       // Function to calculate the area of circle    static double areaOfCircle(double a)    {         // Side of the square        double side = Math.pow(a, (1.0 / 2));         // Diameter of circle        double D = Math.pow(((side * side) + (side * side)),                            (1.0 / 2));         // Radius of circle        double R = D / 2;         // Area of circle        double Area = Math.PI * (R * R);         return Area;    }       // Driver Code    public static void main(String[] args)    {        double areaOfSquare = 4;        System.out.println(areaOfCircle(areaOfSquare));    }} // This code is contribute by Potta Lokesh
# Python program for the above approachimport math # Function to calculate the area of circledef areaOfCircle(a):     # Side of the square    side = a**(1 / 2)     # Diameter of circle    D = ((side * side) + (side * side))**(1 / 2)     # Radius of circle    R = D / 2     # Area of circle    Area = math.pi * (R * R)     return Area # Driver CodeareaOfSquare = 4print(areaOfCircle(areaOfSquare))
// C# code for the above approachusing System; class GFG{       // Function to calculate the area of circle    static double areaOfCircle(double a)    {         // Side of the square        double side = Math.Pow(a, (1.0 / 2));         // Diameter of circle        double D = Math.Pow(((side * side) + (side * side)),                            (1.0 / 2));         // Radius of circle        double R = D / 2;         // Area of circle        double Area = Math.PI * (R * R);         return Area;    }       // Driver Code    public static void Main()    {        double areaOfSquare = 4;        Console.Write(areaOfCircle(areaOfSquare));    }} // This code is contribute by Samim Hossain Mondal.
<script> // Function to calculate the area of circlefunction areaOfCircle(a) {  // declaring pi  let pi = 2 * Math.acos(0.0);   // Side of the square  let side = Math.pow(a, (1.0 / 2));   // Diameter of circle  let D = Math.pow(((side * side) + (side * side)), (1.0 / 2));   // Radius of circle  let R = D / 2;   // Area of circle  let Area = Math.PI * (R * R);   return Area; }//Driver Code let areaOfSquare = 4;document.write(areaOfCircle(areaOfSquare)); // This code is contributed by gfgking</script>
6.283185307179588
Time Complexity: O(1)Auxiliary Space: O(1)
ANKITKUMAR34
gfgking
lokeshpotta20
samim2000
area-volume-programs
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Convex Hull using Divide and Conquer Algorithm
Equation of circle when three points on the circle are given
Circle and Lattice Points
Orientation of 3 ordered points
Program to find slope of a line
Program for Fibonacci numbers
Write a program to print all permutations of a given string
C++ Data Types
Set in C++ Standard Template Library (STL)
Coin Change | DP-7