Given two concentric circles with radius X and Y where (X > Y). Find the area between them.
You are required to find the area of the green region as shown in the following image:
Examples:
Input : X = 2, Y = 1 Output : 9.42478 Input : X = 4, Y = 2 Output : 37.6991
Approach:
The area between the two given concentric circles can be calculated by subtracting the area of the inner circle from the area of the outer circle. Since X>Y. X is the radius of the outer circle.
Therefore, area between the two given concentric circles will be:
?*X2 - ?*Y2
Below is the implementation of the above approach:
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 circlesdouble 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 Programint main(){ int x = 2; int y = 1; cout << calculateArea(x, y); return 0;} |
Java
// Java program to find area between the// two given concentric circlesimport java.io.*;class GFG { // Function to find area between the// two given concentric circlesstatic 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 codepublic 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 Codex = 2y = 1print(calculateArea(x, y)) # This code is contributed # by shashank_sharma |
C#
// C# program to find area between the// two given concentric circlesusing System;class GFG { // Function to find area between the// two given concentric circlesstatic 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 codepublic 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 circlesfunction 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 numberfunction 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 codevar x = 2;var y = 1; // Function calldocument.write(calculateArea(x, y));// This code is contributed by Ankita saini</script> |
9.42478
Time Complexity: O(1)
Auxiliary Space: O(1)
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!


… [Trackback]
[…] Read More here on that Topic: geeksforgeeks.org/program-to-calculate-the-area-between-two-concentric-circles/ […]
… [Trackback]
[…] Find More on that Topic: geeksforgeeks.org/program-to-calculate-the-area-between-two-concentric-circles/ […]
… [Trackback]
[…] Read More to that Topic: geeksforgeeks.org/program-to-calculate-the-area-between-two-concentric-circles/ […]