📜  给定内接正方形的面积时求圆的面积

📅  最后修改于: 2022-05-13 01:56:10.493000             🧑  作者: Mango

给定内接正方形的面积时求圆的面积

给定圆内接正方形的面积为N ,任务是计算正方形内接的圆的面积。

例子:

方法

考虑下图:

  • 设正方形的面积为'A'
  • 正方形的边由 = A**(1/2) 给出
  • 直角三角形由正方形的两条边和圆的直径组成
  • 三角形的斜边将是圆的直径
  • 圆“D”的直径计算为 ((A * A) + (A * A))**(1/2)
  • 圆“r”的半径由 D/2 给出
  • 所得圆的面积为 pi*r*r

下面是上述方法的实现:

C++
#include 
#include
#include 
using namespace std;
 
// Function to calculate the area of circle
double areaOfCircle(double a)
{
    // declaring pi
    double pi=2*acos(0.0);
       
    // Side of the square
    double side = pow(a,(1.0 / 2));
 
    // Diameter of circle
    double D =pow( ((side * side) + (side * side)) ,(1.0 / 2));
 
    // Radius of circle
    double R = D / 2;
 
    // Area of circle
    double Area = pi * (R * R);
 
    return Area;
 
}
 //Driver Code
int main() {
    
    double areaOfSquare = 4;
    cout<


Java
// Java code for the above approach
import java.util.*;
 
class GFG
{
   
    // Function to calculate the area of circle
    static double areaOfCircle(double a)
    {
 
        // Side of the square
        double side = Math.pow(a, (1.0 / 2));
 
        // Diameter of circle
        double D = Math.pow(((side * side) + (side * side)),
                            (1.0 / 2));
 
        // Radius of circle
        double R = D / 2;
 
        // Area of circle
        double Area = Math.PI * (R * R);
 
        return Area;
    }
   
    // Driver Code
    public static void main(String[] args)
    {
        double areaOfSquare = 4;
        System.out.println(areaOfCircle(areaOfSquare));
    }
}
 
// This code is contribute by Potta Lokesh


Python3
# Python program for the above approach
import math
 
# Function to calculate the area of circle
def areaOfCircle(a):
 
    # Side of the square
    side = a**(1 / 2)
 
    # Diameter of circle
    D = ((side * side) + (side * side))**(1 / 2)
 
    # Radius of circle
    R = D / 2
 
    # Area of circle
    Area = math.pi * (R * R)
 
    return Area
 
# Driver Code
areaOfSquare = 4
print(areaOfCircle(areaOfSquare))


C#
// C# code for the above approach
using System;
 
class GFG
{
   
    // Function to calculate the area of circle
    static double areaOfCircle(double a)
    {
 
        // Side of the square
        double side = Math.Pow(a, (1.0 / 2));
 
        // Diameter of circle
        double D = Math.Pow(((side * side) + (side * side)),
                            (1.0 / 2));
 
        // Radius of circle
        double R = D / 2;
 
        // Area of circle
        double Area = Math.PI * (R * R);
 
        return Area;
    }
   
    // Driver Code
    public static void Main()
    {
        double areaOfSquare = 4;
        Console.Write(areaOfCircle(areaOfSquare));
    }
}
 
// This code is contribute by Samim Hossain Mondal.


Javascript


输出
6.283185307179588

时间复杂度:O(1)
辅助空间: O(1)