Programa para calcular el área entre dos Círculos Concéntricos

Dadas dos circunferencias concéntricas de radio X e Y donde ( X > Y ). Encuentra el área entre ellos. 
Debe encontrar el área de la región verde como se muestra en la siguiente imagen: 
 

Ejemplos: 

Input : X = 2, Y = 1
Output : 9.42478

Input : X = 4, Y = 2
Output : 37.6991

Método:
El área entre los dos círculos concéntricos dados se puede calcular restando el área del círculo interior del área del círculo exterior. Dado que X>Y . X es el radio del círculo exterior.
Por lo tanto, el área entre los dos círculos concéntricos dados será: 

π*X2 - π*Y2

A continuación se muestra la implementación del enfoque anterior:

C++

// C++ program to find area between the
// two given concentric circles
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to find area between the
// two given concentric circles
double calculateArea(int x, int y)
{
    // Declare value of pi
    double pi = 3.1415926536;
 
    // Calculate area of outer circle
    double arx = pi * x * x;
 
    // Calculate area of inner circle
    double ary = pi * y * y;
 
    // Difference in areas
    return arx - ary;
}
 
// Driver Program
int main()
{
    int x = 2;
    int y = 1;
 
    cout << calculateArea(x, y);
 
    return 0;
}

Java

// Java program to find area between the
// two given concentric circles
import java.io.*;
 
class GFG
{
     
// Function to find area between the
// two given concentric circles
static double calculateArea(int x, int y)
{
    // Declare value of pi
    double pi = 3.1415926536;
 
    // Calculate area of outer circle
    double arx = pi * x * x;
 
    // Calculate area of inner circle
    double ary = pi * y * y;
 
    // Difference in areas
    return arx - ary;
}
 
// Driver code
public static void main (String[] args)
{
    int x = 2;
    int y = 1;
    System.out.println (calculateArea(x, y));
}
}
 
// This code is contributed by jit_t.

Python3

# Python3 program to find area between 
# the two given concentric circles
 
# Function to find area between the
# two given concentric circles
def calculateArea(x, y):
 
    # Declare value of pi
    pi = 3.1415926536
 
    # Calculate area of outer circle
    arx = pi * x * x
 
    # Calculate area of inner circle
    ary = pi * y * y
 
    # Difference in areas
    return arx - ary
 
# Driver Code
x = 2
y = 1
 
print(calculateArea(x, y))
 
# This code is contributed
# by shashank_sharma

C#

// C# program to find area between the
// two given concentric circles
using System;
 
class GFG
{
     
// Function to find area between the
// two given concentric circles
static double calculateArea(int x, int y)
{
    // Declare value of pi
    double pi = 3.1415926536;
 
    // Calculate area of outer circle
    double arx = pi * x * x;
 
    // Calculate area of inner circle
    double ary = pi * y * y;
 
    // Difference in areas
    return arx - ary;
}
 
// Driver code
public static void Main ()
{
    int x = 2;
    int y = 1;
    Console.WriteLine(calculateArea(x, y));
}
}
 
// This code is contributed by Code_Mech.

PHP

<?php
// PHP program to find area between the
// two given concentric circles
 
// Function to find area between the
// two given concentric circles
function calculateArea($x, $y)
{
    // Declare value of pi
    $pi = 3.1415926536;
 
    // Calculate area of outer circle
    $arx = $pi * $x * $x;
 
    // Calculate area of inner circle
    $ary = $pi * $y * $y;
 
    // Difference in areas
    return ($arx - $ary);
}
 
// Driver Code
$x = 2;
$y = 1;
 
echo calculateArea($x, $y);
 
// This code is contributed by akt_mit
?>

Javascript

<script>
 
// Javascript program to find area between
// the two given concentric circles
 
// Function to find
// nth concentric hexagon number
function calculateArea(x, y)
{
     
    // Declare value of pi
    var pi = 3.1415926536;
 
    // Calculate area of outer circle
    var arx = pi * x * x;
 
    // Calculate area of inner circle
    var ary = pi * y * y;
     
    // Difference in areas
    return arx - ary;
}
 
// Driver code
var x = 2;
var y = 1;
         
// Function call
document.write(calculateArea(x, y));
 
// This code is contributed by Ankita saini
 
</script>
Producción: 

9.42478

 

Complejidad de tiempo: O(1)

Espacio Auxiliar: O(1)
 

Publicación traducida automáticamente

Artículo escrito por Abdullah Aslam 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 *