给定半径为R的半圆,任务是找到可以在该半圆上内接的最大圆的面积。
例子:
Input: R = 2
Output: 3.14
Input: R = 8
Output: 50.24
方法:设R为半圆的半径
- 对于可以在该半圆内切出的最大圆,圆的直径必须等于半圆的半径。
- 因此,如果半圆的半径为R ,则最大内切圆的直径将为R。
- 因此,内切圆的半径必须为R / 2
- 因此,最大圆的面积将是
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