×

Find out the area between two concentric circles

You have given two values of the radius of two circles. You have to find out the area between these two circles. Let's take an example -

Drawing Tool

For the above diagram, we can find two circles whose centre is a single point. So, they are concentric circles. Suppose the centre point is 'O', the radius of the inner circle is a, and the outer circle is b. In the question, the value of a and b will be given, and you have to calculate the area between these two circles (the coloured part of the diagram).

Input- 3, 4

Output- 21.99

Explanation- The area of the inner circle is 28.27 units, and the area of the outer circle is 50.26. So, the area between them = 50.26 - 28.27 = 21.99.

Note: -

What are concentric circles?

There are different structures like spheres, rings, and circles. When two circles have the same centre and different radii, then they are called concentric circles. Two concentric circles must have a different radius. The difference between the areas of two concentric circles is called the annulus.

Algorithm:-

Step 1: Start

Step 2: Two values are taken from the user

Step 3: Area of inner circle calculated and stored.

Step 4: Area of outer circle calculated and stored.

Step 5: Expected area will be the difference between these two areas.

Step 6: The value will be printed.

Step 7: Stop.

Explanation of the Algorithm: Here, the algorithm is the simplest one. The area of the outer circle is greater than the inner circle, so the radius of the outer circle will be greater than the inner circle. If we take a as the radius of the inner circle, and b as the radius of the outer circle then b>a. The area of the circle is calculated by the formula: A = pie * r * r ( pie = 24/7, r is the radius).

Code: -

#include <bits/stdc++.h>
using namespace std;
// function to calculate the area of circle
float area ( int r ){
// the answer will be in decimal point so we have to take float
         float ans = 0;
        ans = (24/7) * r * r;
        return ans;
}
/* Driver code*/
int main()
{
	Int a =0 ,b =0;
            Cin>> a>>b;
	cout << "Area between the circle with radius " << a << " and radius  " << b << " is "<<area(a)-area(b)<<endl;
	a = 7, b = 4;
	cout << "Area between the circle with radius " << a << " and radius  " << b << " is "<<area(a)-area(b)<<endl;	
a = 2, b = 0;
	cout << "Area between the circle with radius " << a << " and radius  " << b << " is "<<area(a)-area(b)<<endl;	
return 0;
}

Output: 

Area between the circle with radius 4 and radius 3 is 21.99.
Area between the circle with radius 7 and radius 4 is 103.67.
Area between the circle with radius 2 and radius 0 is 12.56.

Complexity Analysis: -

Time complexity- Here the complexity will be constant because there is not any loop or recursion. Complexity will be O(1).

Space complexity- In this solution, we use constant memory. So, space complexity will be O(1).

Another Approach

This problem can be solved by another approach, If the radius is a and b, then we can calculate

(a + b ) * (a – b) and store it. After that, we can multiply it by the value of the pie then our answer will be ready. In this case, we can avoid overflow due to multiplication of a (square of a) or multiplication of b (square of b).

Code:

#include <bits/stdc++.h>
using namespace std;
/* Driver code*/
int main()
{
	Int a =0 ,b =0;
            Cin>> a>>b;
            Float ans = (24/7) * ( a + b) * ( a – b);
	cout << "Area between the circle with radius " << a << " and radius  " << b << " is " << ans << endl;
	a = 7, b = 4;
Float ans = (24/7) * ( a + b) * ( a – b);


	cout << "Area between the circle with radius " << a << " and radius  " << b << " is "<< ans <<endl;	
a = 2, b = 0;
Float ans = (24/7) * ( a + b) * ( a – b);
	cout << "Area between the circle with radius " << a << " and radius  " << b << " is " << ans <<endl;	
return 0;
}

Output: 

Area between the circle with radius 4 and radius 3 is 21.99.
Area between the circle with radius 7 and radius 4 is 103.67.
Area between the circle with radius 2 and radius 0 is 12.56.

Related Topics

Find out the area between two concentric circles

You have given two values of the radius of two circles. You have to find out the area between these two circles. Let's take an example - For the above diagram,...

3 minutes read.

Delete a Node without head pointer from the linked list

Delete a Node without head pointer from the linked list This article will explain how to delete a node without a head pointer from the linked list. We have given a...

2 minutes read.

Threaded Binary Trees

Introduction Threaded Binary Trees (TBTs) are an enhancement of normal binary trees intended for in-order traversal only. This means that this data structure is developed with the objective of making the...

12 minutes read.

Splay Tree

Splay Tree A splay tree is a self-balanced or self-adjusted binary search tree. We can say, Splay Tree is used in some cases where some elements or data are accessed more...

8 minutes read.

Red-black Tree in Data Structures?

A type of binary tree which is known as the Red-Black tree, is a specialized and unique tree. What is the urgency or, to be more precise, the necessity of...

10 minutes read.

Binary Search

Binary Search: When there is a large data structure, the linear search takes a lot of time to search the element. The binary search was developed to overcome the lack...

7 minutes read.

Permutation Sort or Bogo Sort

In Permutation Sort or Bogo Sort, you have been given one array, which consists of different values. You have to sort the array using BOGO sort. Let’s take an example: Input-...

3 minutes read.

Heap Sort vs Merge Sort

In this article, we are going to discuss the Heap Sort, Merge sort and the difference between them. What is Heap Sort? Heap – A heap is an abstract data type categorised...

7 minutes read.

Stack Data Structure

The stack is a non-primitive and linear data structure. It works on the principle of LIFO (Last In First Out). That is, the element that is added to the end...

3 minutes read.

Bubble Sort vs Merge Sort

In this article, we are going to compare two sorting techniques, Bubble sort and Merge Sort. In starting, we will first discuss the idea of sorting an array using bubble...

7 minutes read.

Queue operations in Data Structure

Queue - Queue is a linear data structure or first in first out data structure means the first element added in the queue will be removed first and the last...

7 minutes read.

2-3 Trees and Basic Operations on them

2-3 Trees, like any other AVL trees or B-trees, are just a type of Height Balanced Tree. 2-3 Trees are the B-trees of order 3. Like every other B-tree, the...

4 minutes read.

Arrange consonants and vowels nodes in a linked list

Arrange consonants and vowels nodes in a linked list In this problem, we have given a singly linked list. Here we will arrange the consonants and vowels nodes of the list...

2 minutes read.

Linked List Representation of Binary Tree

As we all know, a binary tree has a maximum of two children and helps us manage the info correctly. The word binary itself represents its meaning; we know that...

4 minutes read.

Breadth First Search

Breadth First Search Breadth first search is a graph traversing algorithm. In this, we start traversing from the source node or any selected node and traverse the graph layer by layer....

6 minutes read.

Singly Linked list

Singly Linked list A singly linked list is a kind of linked list which is unidirectional. If we talk about singly linked list, then we can say it can be traversed...

3 minutes read.

Preorder Traversal of Binary Trees

In general, Stack, Array, Queue, and other linear data structures only have one way to traverse the data. However, there are numerous ways to traverse through the data in a hierarchical...

3 minutes read.

Doubly Linked List

Doubly Linked List Doubly linked list is another kind of Linked list. Doubly linked list contains two pointers for navigation. In this, we can traverse the list in both directions, either...

4 minutes read.

Introduction and Implementation of Bloom Filter

It often happens with many of us that when we create an account on some applications like Github, it shows us that the username already exists. You can add some...

4 minutes read.

Binary Tree to Doubly Linked List

Binary Tree to Doubly Linked List This article will explain how to convert the given binary tree into a Doubly Linked List. The left and right pointers in tree nodes are...

2 minutes read.