Dada la ecuación de un círculo como cuerda, encuentre el área

Dada una ecuación del círculo X 2 + Y 2 = R 2 cuyo centro en el origen (0, 0) y el radio es R. La tarea es encontrar el área del círculo.
Ejemplos: 
 

Input : 
X*X + Y*Y = 25
Output :
The area of circle centered at origin  is : 78.55

Input : 
X*X + Y*Y = 64
Output :
The area of circle centered at origin  is : 201.088

Acercarse

  • Dada una ecuación X 2 + Y 2 = R 2 y almacenarla en la string ‘str’.
  • Cuente la longitud de la string y guárdela en ‘len’.
  • Inicie el bucle de 0 a len – 1 y verifique si str[i] == ‘=’.
  • Almacene los caracteres después de ‘=’ en la variable de string st.
  • Convierta la string ‘st’ en dígitos y guárdela en ‘radius_square’.
  • Use la fórmula Pi * R 2 para encontrar el área del círculo (multiplique por Pi).

C++

// C++ program to find area of circle
// when equation of circle give.
 
#include <bits/stdc++.h>
#define PI 3.142
using namespace std;
 
// Function to find the area
double findArea(double radius)
{
    return PI * pow(radius, 2);
}
 
// Function to return the value of radius
static double findradius(string str)
{
     
    // Initialization
    double radius = 0;
     
    // For storing the value of R*R
    string st = "";
 
    // For counting the number of
    // spaces in the string
    int c = 0;
 
    // calculate the length of the
    int len = str.length();
 
    // getting the value of R*R
    // After = sign
    for (int i = 0; i < len; i++) {
        if (str[i] == '=') {
            c = 1;
        }
        else if (c == 1 && str[i] != ' ') {
            st = st + str[i];
        }
    }
 
    // Converting the digits into integer
    // Taking square root of that number
    radius = (double)sqrt(stoi(st));
    return radius;
}
 
int main()
{
 
    // Static input for equation
    // of circle
    string str = "X*X + Y*Y = 100";
 
    // calling the Function
    double radius = findradius(str);
 
    // Display the result
    cout << "The area of circle " <<
       "centered at origin is : " <<
           findArea(radius) << endl;
 
    return 0;
}

Java

// Java program to find area of circle
// when equation of circle give.
import java.io.*;
 
public class GFG {
 
    static double PI = 3.142;
     
    // Function to find the area
    static double findArea(double radius)
    {
        return PI * Math.pow(radius, 2);
    }
     
    // Function to return the value of radius
    static double findradius(String str)
    {
        double radius = 0;
         
        // For storing the value of radius * radius
        String st = "";
 
        // For counting the number of spaces
        // in the string
        int c = 0;
 
        // calculate the length of the
        int len = str.length();
         
        // getting the value of radius * radius
        // After = sign
        for (int i = 0; i < len; i++) {
            if (str.charAt(i) == '=') {
                c = 1;
            }
            else if (c == 1 && str.charAt(i) != ' ')
            {
                st = st + str.charAt(i);
            }
        }
 
        // Converting the digits into integer
        // Taking square root of that number
        if (c == 1)
            radius = (double)Math.sqrt(
                            Integer.parseInt(st));
        return radius;
    }
 
    public static void main(String[] args)
    {
 
        // Static input for equation of circle
        String str = "X*X + Y*Y = 100";
 
        // calling the Function
        double radius = findradius(str);
 
        // Display the result
        System.out.println("The area of circle"
                  + " centered at origin is : "
                              + findArea(radius));
    }
}

Python3

# python program to find area of circle
# when equation of circle give.
 
import math
 
# Function to find the area
def findArea(radius):
     
    return math.pi * pow(radius, 2)
 
# Function to return the value of radius
def findradius(str):
     
    #Initialization
    radius = 0
     
    # For storing the value of R*R
    st = ""
 
    # For counting the number of
    # spaces in the string
    c = 0
 
    # calculate the length of the
    Len = len(str)
 
    # getting the value of R*R
    # After = sign
    for i in range(0, Len):
        if (str[i] == '='):
            c = 1
        elif (c == 1 and str[i] != ' '):
            st = st + str[i]
         
    # Converting the digits into integer
    # Taking square root of that number
    radius = float(math.sqrt(float(st)))
    return radius
 
# Static input for equation
# of circle
str = "X*X + Y*Y = 100"
 
# calling the Function
radius = findradius(str)
 
# Display the result
print( "The area of circle " ,
"centered at origin is : " ,
    (findArea(radius)))
 
 
# This code is contributed by Sam007.

C#

// C# program to find area of circle
// when equation of circle give.
using System;
 
class GFG
{
    // Function to find the area
    static double findArea(double radius)
    {
        return Math.PI * Math.Pow(radius, 2);
    }
     
    // Function to return the value of radius
    static double findradius(string str)
    {
        double radius = 0;
         
        // For storing the value
        // of radius * radius
        String st = "";
 
        // For counting the number
        // of spaces in the string
        int c = 0;
 
        // calculate the length of the
        int len = str.Length;
         
        // getting the value of radius * radius
        // After = sign
        for (int i = 0; i < len; i++)
        {
            if (str[i] == '=')
            {
                c = 1;
            }
            else if (c == 1 && str[i] != ' ')
            {
                st = st + str[i];
            }
        }
 
        // Converting the digits into integer
        // Taking square root of that number
        if (c == 1)
            radius = (double)Math.Sqrt(
                        int.Parse(st));
        return radius;
    }
 
    // Driver code
    public static void Main()
    {
        // Static input for equation of circle
        string str = "X*X + Y*Y = 100";
 
        // calling the Function
        double radius = findradius(str);
 
        // Display the result
        Console.WriteLine("The area of circle" +
                          " centered at origin is : " +
                          System.Math.Round(findArea(radius),1));
    }
}
 
// This code is contributed by Sam007

Javascript

<script>
 
// JavaScript program to find area of circle
// when equation of circle give.
 
    let PI = 3.142;
       
    // Function to find the area
    function findArea(radius)
    {
        return PI * Math.pow(radius, 2);
    }
       
    // Function to return the value of radius
    function findradius(str)
    {
        let radius = 0;
           
        // For storing the value of radius * radius
        let st = "";
   
        // For counting the number of spaces
        // in the string
        let c = 0;
   
        // calculate the length of the
        let len = str.length;
           
        // getting the value of radius * radius
        // After = sign
        for (let i = 0; i < len; i++) {
            if (str[i] == '=') {
                c = 1;
            }
            else if (c == 1 && str[i] != ' ')
            {
                st = st + str[i];
            }
        }
   
        // Converting the digits into integer
        // Taking square root of that number
        if (c == 1)
            radius = Math.sqrt(
                            parseInt(st));
        return radius;
    }
 
// Driver program
 
        // Static input for equation of circle
        let str = "X*X + Y*Y = 100";
   
        // calling the Function
        let radius = findradius(str);
   
        // Display the result
        document.write("The area of circle"
                  + " centered at origin is : "
                              + findArea(radius));
         
        // This code is contributed by susmitakundugoaldanga.
</script>
Producción: 

The area of circle centered at origin is : 314.2

 

Complejidad temporal: O(n)
Espacio auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por Manish_100 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *