Sum of area of alternative concentric circle with radius 1,2,3,4..........N
Last Updated : 20 Jan, 2022
Given that Concentric circle of radii 1,2,3,4..........N cm are drawn. The interior of the smallest circle is colored white and angular regions are colored alternately green and white so that no two adjacent regions are of the same color. The task is to find the total area of the green region in sq cm.
Examples:
Input: N=100
Output: 15865.042900628456
Input: N=10
Output: 172.78759594743863
Approach: Area of the first green region would be-
[?(R2²- R1²)]
Similarly, the area of all alternative green circles would be-
[?(R4²- R3²)], [?(R6²- R5²)].....
The total area of the green region is the sum of the area of the green region is-
A = [ ? { (R2² - R1²) + (R4² - R3²) + (R6² - R5²) ............. (R(N)² - R(N-1)²}]
A = [ ? { ((R2 - R1)(R2 + R1)) + ((R4 - R3)(R4 + R3)) + ((R6 - R5)(R6 + R5)) ............. ((RN - R(N - 1)(RN + R(N - 1)) } ]
Since the difference between the radius of 2 concentric circles is only 1 cm so R(N) - R(N - 1) = 1. Hence,
A = [ ? {R1 + R2 + R3 + R4 + R5 + R6 .............R(N-1) + R(N) } ]
(R1 + R2 + R3 + R4 + R5 + R6 .............R(N-1) + R(N) forms an arithmetic progression so we have to find the sum of arithmetic progression with starting radius as 1 and last radius as N with a common difference of 1.
Sum of A.P. is-
SN = N * (2 * a +(N - 1) * d) / 2
or
SN = N * (a + l) / 2
Thus, the area of the green region is-
A = Sn * ?
Below is the implementation of the above approach:
C++ // C++ code for the above approach #include <bits/stdc++.h> using namespace std; // Function to calculate area // of concentric circles double area(int N, int a, int l) { // Formula to find sum of // Arithmetic Progression double S = N * (a + l) / 2; // return area return S * M_PI; } // Driver code int main() { // N is number of concentric circles int N = 100; // Radius of interior circle int a = 1; // l radius of exterior circle int l = N; // r is result double r = area(N, a, l); // Print result cout << fixed << setprecision(12) << r; } // This code is contributed by Samim Hossain Mondal.
Java // Java code for the above approach class GFG { // Function to calculate area // of concentric circles static double area(int N, int a, int l) { // Formula to find sum of // Arithmetic Progression double S = N * (a + l) / 2; // return area return S * Math.PI; } // Driver code public static void main(String args[]) { // N is number of concentric circles int N = 100; // Radius of interior circle int a = 1; // l radius of exterior circle int l = N; // r is result double r = area(N, a, l); // Print result System.out.println(r); } } // This code is contributed by gfgking
Python3 # import pi from math module from math import pi # Function to calculate area # of concentric circles def area(N,a): # Formula to find sum of # Arithmetic Progression S = N * (a + l) / 2 # return area return S * pi # N is number of concentric circles N = 100 # Radius of interior circle a = 1 # l radius of exterior circle l = N # r is result r = area(N, a) # Print result print(r)
C# // C# program for the above approach using System; class GFG { // Function to calculate area // of concentric circles static double area(int N, int a, int l) { // Formula to find sum of // Arithmetic Progression double S = N * (a + l) / 2; // return area return S * Math.PI; } // Driver Code: public static void Main() { // N is number of concentric circles int N = 100; // Radius of interior circle int a = 1; // l radius of exterior circle int l = N; // r is result double r = area(N, a, l); // Print result Console.WriteLine(r); } } // This code is contributed by Samim Hossain Mondal.
JavaScript <script> // JavaScript code for the above approach // Function to calculate area // of concentric circles function area(N, a) { // Formula to find sum of // Arithmetic Progression S = N * (a + l) / 2 // return area return S * Math.PI } // N is number of concentric circles N = 100 // Radius of interior circle a = 1 // l radius of exterior circle l = N // r is result r = area(N, a) // Print result document.write(r) // This code is contributed by Potta Lokesh </script>
Time Complexity: O(1)
Auxiliary Space: O(1)
Similar Reads
Radius of a circle having area equal to the sum of area of the circles having given radii Given two integers r1 and r2, representing the radius of two circles, the task is to find the radius of the circle having area equal to the sum of the area of the two circles having given radii. Examples: Input:r1 = 8r2 = 6Output:10Explanation:Area of circle with radius 8 = 201.061929 Area of a circ
4 min read
Area of Equilateral triangle inscribed in a Circle of radius R Given an integer R which denotes the radius of a circle, the task is to find the area of an equilateral triangle inscribed in this circle. Examples: Input: R = 4 Output: 20.784 Explanation: Area of equilateral triangle inscribed in a circle of radius R will be 20.784, whereas side of the triangle wi
4 min read
Program to calculate the area between two Concentric Circles 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 tw
4 min read
Count points from an array that lies inside a semi-circle Given two pairs (X, Y), (P, Q) and R the coordinate of the center of semi-circle, coordinate of the intersection of semicircle and diameter of the semicircle and, the radius of the semicircle, and an array arr[] of dimension N*2 consisting of the coordinates of few points, the task is to find the nu
7 min read
Sum of first n terms of a given series 3, 6, 11, ..... Given a series and a number n, the task is to find the sum of its first n terms. Below is the series: 3, 6, 11, 20, .... Examples: Input: N = 2 Output: 9 The sum of first 2 terms of Series is 3 + 6 = 9 Input: N = 3 Output: 20 The sum of first 3 terms of Series is 3 + 6 + 11 = 20 Approach: This probl
5 min read