📌  相关文章
📜  找出正方形中四个半圆的交点形成的阴影区域的面积

📅  最后修改于: 2021-04-29 11:14:37             🧑  作者: Mango

给定正方形a边的长度,任务是找到正方形中四个半圆的交点形成的阴影区域的面积,如下图所示:

例子:

方法:阴影区域的面积为:

半圆的面积为(3.14 * r 2 )/ 2 ,其中r是等于a / 2的半圆的半径。
因此,阴影区域的面积= 4 *(3.14 *(a * a)/ 8)– a * a

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to return the area
// of the shaded region
float findAreaShaded(float a)
{
 
    // Area of the square
    float sqArea = a * a;
 
    // Area of the semicircle
    float semiCircleArea = (3.14 * (a * a) / 8);
 
    // There are 4 semicircles
    // shadedArea = Area of 4 semicircles - Area of square
    float ShadedArea = 4 * semiCircleArea - sqArea;
 
    return ShadedArea;
}
 
// Driver code
int main()
{
    float a = 10;
    cout << findAreaShaded(a);
 
    return 0;
}


Java
// Java implementation of the approach
class GFG {
 
    // Function to return the area
    // of the shaded region
    static float findAreaShaded(float a)
    {
 
        // Area of the square
        float sqArea = a * a;
 
        // Area of the semicircle
        float semiCircleArea = (float)(3.14 * (a * a) / 8);
 
        // There are 4 semicircles
        // shadedArea = Area of 4 semicircles - Area of square
        float ShadedArea = 4 * semiCircleArea - sqArea;
 
        return ShadedArea;
    }
 
    // Driver code
    public static void main(String[] args)
    {
        float a = 10;
        System.out.println(findAreaShaded(a));
    }
}


Python3
# Python3 implementation of the approach
 
# Function to return the area
# of the shaded region
def findAreaShaded(a):
     
    # Area of the square
    sqArea = a * a;
 
    # Area of the semicircle
    semiCircleArea = (3.14 * (a * a ) / 8)
 
    # There are 4 semicircles
    # shadedArea = Area of 4 semicircles - Area of square
    ShadedArea = 4 * semiCircleArea - sqArea ;
 
    return ShadedArea;
 
# Driver code
if __name__ == '__main__':
    a = 10
    print(findAreaShaded(a))


C#
// C# implementation of the approach
using System;
 
class GFG
{
 
    // Function to return the area
    // of the shaded region
    static float findAreaShaded(float a)
    {
 
        // Area of the square
        float sqArea = a * a;
 
        // Area of the semicircle
        float semiCircleArea = (float)(3.14 * (a * a) / 8);
 
        // There are 4 semicircles
        // shadedArea = Area of 4 semicircles - Area of square
        float ShadedArea = 4 * semiCircleArea - sqArea;
 
        return ShadedArea;
    }
 
    // Driver code
    public static void Main()
    {
        float a = 10;
        Console.WriteLine(findAreaShaded(a));
    }
}
 
// This code is contributed by mohit kumar 29


PHP


Javascript


输出:
57