📜  刻在矩形上的圆的面积,刻在半圆上

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

给定一个半径为R的半圆,该半圆内接一个长度为L且宽度为B的矩形,而该矩形又内接一个半径为r的圆。任务是找到半径为r的圆的面积。
例子:

Input : R = 2
Output : 1.57

Input : R = 5
Output : 9.8125

方法

C++
// C++ Program to find the area of the circle
// inscribed within the rectangle which in turn
// is inscribed in a semicircle
#include 
using namespace std;
 
// Function to find the area of the circle
float area(float r)
{
 
    // radius cannot be negative
    if (r < 0)
        return -1;
 
    // area of the circle
    float area = 3.14 * pow(r / (2 * sqrt(2)), 2);
    return area;
}
 
// Driver code
int main()
{
    float a = 5;
    cout << area(a) << endl;
    return 0;
}


Java
// Java Program to find the area of the circle
// inscribed within the rectangle which in turn
// is inscribed in a semicircle
 
import java.io.*;
 
class GFG {
 
 
// Function to find the area of the circle
static float area(float r)
{
 
    // radius cannot be negative
    if (r < 0)
        return -1;
 
    // area of the circle
    float area = (float)(3.14 * Math.pow(r / (2 * Math.sqrt(2)), 2));
    return area;
}
 
// Driver code
 
    public static void main (String[] args) {
            float a = 5;
    System.out.println( area(a));
    }
}
 
 // This code is contributed by ajit


Python3
# Python 3 Program to find the
# area of the circle inscribed
# within the rectangle which in
# turn is inscribed in a semicircle
from math import pow, sqrt
 
# Function to find the area
# of the circle
def area(r):
     
    # radius cannot be negative
    if (r < 0):
        return -1
 
    # area of the circle
    area = 3.14 * pow(r / (2 * sqrt(2)), 2);
     
    return area;
 
# Driver code
if __name__ == '__main__':
    a = 5
    print("{0:.6}".format(area(a)))
 
# This code is contributed By
# Surendra_Gangwar


C#
// C# Program to find the area of
// the circle inscribed within the
// rectangle which in turn is
// inscribed in a semicircle
using System;
 
class GFG
{
 
// Function to find the area
// of the circle
static float area(float r)
{
 
    // radius cannot be negative
    if (r < 0)
        return -1;
 
    // area of the circle
    float area = (float)(3.14 * Math.Pow(r /
                        (2 * Math.Sqrt(2)), 2));
    return area;
}
 
// Driver code
static public void Main (String []args)
{
    float a = 5;
    Console.WriteLine(area(a));
}
}
 
// This code is contributed
// by Arnab Kundu


PHP


Javascript


输出:
9.8125