📜  内有正方形和圆形的圆的面积

📅  最后修改于: 2021-04-25 01:14:18             🧑  作者: Mango

鉴于其保持在一个圈子里面一个广场的一侧。它一直在扩展,直到所有四个顶点都接触到圆的圆周为止。现在,另一个较小的圆保留在正方形内部,并且一直扩大,直到其圆周接触正方形的所有四个边为止。外圈和内圈形成一个环。找到该阴影部分的区域,如下图所示。

例子:

方法:

从上图可以得出R = a / sqrt(2) ,其中a是正方形的边长。外圆的面积为(pi * R * R)

s1为外圆的面积(pi * R * R)s2为内圆的面积(pi * r * r) 。那么环的面积是s1 – s2
下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
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;
}


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));
    }
}


Python3
# 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)))


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


Javascript


输出:
7.06858