📜  半圆可内接的最大圆面积

📅  最后修改于: 2021-10-23 09:09:03             🧑  作者: Mango

给定一个半径为R的半圆,任务是找到可以内接在半圆中的最大圆的面积。
例子:

Input: R = 2
Output: 3.14

Input: R = 8
Output: 50.24

方法:设R为半圆的半径

  1. 对于可内接在该半圆中的最大圆,圆的直径必须等于半圆的半径。
  2. 因此,如果半圆的半径为R ,则最大内切圆的直径为R
  3. 因此内切圆的半径必须是R/2
  4. 因此最大圆的面积为
Area of circle = pi*Radius2
               = pi*(R/2)2

since the radius of largest circle is R/2
where R is the radius of the semicircle

下面是上述方法的实现:

C++
// C++ Program to find the biggest circle
// which can be inscribed within the semicircle
 
#include 
using namespace std;
 
// Function to find the area
// of the circle
float circlearea(float R)
{
 
    // Radius cannot be negative
    if (R < 0)
        return -1;
 
    // Area of the largest circle
    float a = 3.14 * R * R / 4;
 
    return a;
}
 
// Driver code
int main()
{
    float R = 2;
    cout << circlearea(R) << endl;
 
    return 0;
}


Java
// Java Program to find the biggest circle
// which can be inscribed within the semicircle
class GFG
{
     
    // Function to find the area
    // of the circle
    static float circlearea(float R)
    {
     
        // Radius cannot be negative
        if (R < 0)
            return -1;
     
        // Area of the largest circle
        float a = (float)((3.14 * R * R) / 4);
     
        return a;
    }
     
    // Driver code
    public static void main (String[] args)
    {
        float R = 2;
        System.out.println(circlearea(R));
    }
}
 
// This code is contributed by AnkitRai01


Python3
# Python3 Program to find the biggest circle
# which can be inscribed within the semicircle
 
# Function to find the area
# of the circle
def circlearea(R) :
 
    # Radius cannot be negative
    if (R < 0) :
        return -1;
 
    # Area of the largest circle
    a = (3.14 * R * R) / 4;
 
    return a;
 
# Driver code
if __name__ == "__main__" :
 
    R = 2;
    print(circlearea(R)) ;
     
# This code is contributed by AnkitRai01


C#
// C# Program to find the biggest circle
// which can be inscribed within the semicircle
using System;
 
class GFG
{
     
    // Function to find the area
    // of the circle
    static float circlearea(float R)
    {
     
        // Radius cannot be negative
        if (R < 0)
            return -1;
     
        // Area of the largest circle
        float a = (float)((3.14 * R * R) / 4);
     
        return a;
    }
     
    // Driver code
    public static void Main (string[] args)
    {
        float R = 2;
        Console.WriteLine(circlearea(R));
    }
}
 
// This code is contributed by AnkitRai01


Javascript


输出:
3.14