×

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

Array vs Linked List: Data Structure

Data structure: Difference Between Array and Linked List What is Array? An array is a linear data structure that can store similar data items for further processing. The similar data items...

3 minutes read.

What is the Use of Segment Trees in Data Structure?

Segment trees Segment trees are also called statistical trees in computer science. They are a type of tree data structure. Segment trees are used to store information regarding segments and intervals....

6 minutes read.

Semi-Structured data

In this article, we will discuss the semi-structured data. Data can be defined as the distinct piece of information that is gathered and translated for some purpose. It can be...

5 minutes read.

Radix Sort

Radix Sort: The radix sort is a non-comparative integer sorting algorithm that sorts the elements by grouping the individual digits of the same location. It shares the same significant position...

4 minutes read.

Remove duplicates from an unsorted Linked List

Remove duplicates from an unsorted Linked List This article will explain how we can remove duplicates from unsorted linked lists. Here we have given an unsorted singly linked list and will...

3 minutes read.

Binary Tree Inorder Traversal

The binary tree is a type of tree in which each and every node has atleast two children except the leaf nodes. We have various operations in the binary tree,...

4 minutes read.

Complete Binary tree

In this article, we will discuss the complete binary tree. But before start discussing the complete binary tree, we should first see a brief description of a binary tree. What is...

7 minutes read.

Cocktail Sort

C Program executes cocktail sort. Combo sort is a somewhat straightforward arranging calculation initially planned by Wlodzimierz Dobosiewicz and Artur Borowy in 1980, later rediscovered by Stephen Lacey and Richard Box...

5 minutes read.

Construction of B tree in Data Structure

A B-tree is a type of balanced tree data structure that is commonly used in file systems and databases to improve the efficiency of search, insert, and delete operations. The structure...

4 minutes read.

Merge Sort

Merge Sort is one of the most widely used sorting algorithms, and it is based on the Divide and Conquer principle. A problem is subdivided into multiple sub-problems in this method....

8 minutes read.

Recursion - Factorial and Fibonacci

In this article, we will learn how to find the factorial of a number and the Fibonacci series up to n using the recursion method. What is recursion? Defining anything in terms...

7 minutes read.

Minimum Spanning Tree

Before getting to know about the minimum spanning tree, we should first discuss about what is a spanning tree. A spanning tree is basically a sub or minimized graph that...

7 minutes read.

Post-order traversal in a binary tree

We all know that postorder is a form of tree traversal to visit the tree's nodes, and it helps us reach out to the tree's nodes. Postorder means visiting the...

4 minutes read.

Convert binary tree to a doubly linked list

Implementation //creating a C++ program for the transition of a binary tree into a linked list. #include <iostream> using namespace std; /* Firstly, let’s create a binary tree that will help us in setting...

4 minutes read.

Function to Delete a Leaf Node from a Binary Tree

Implementation // We are writing a C++ code to eliminate all the leaves from the given value.  #include <bits/stdc++.h> using namespace std; // creating a new binary tree node struct __nod { int record; struct __nod *Lft,...

4 minutes read.

Binary Search Tree

Binary Search Tree: A binary search tree is a type of tree in which every node is organized in the sorted order. It is also called an ordered binary tree. Properties...

4 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.

Convert Binary Tree into a Threaded Binary Tree

Implementation /*Writing a C++ program that will help us change the binary tree into a threaded binary tree and help us transform. */ #include <bits/stdc++.h> using namespace std; /*Creating the structure of a node...

11 minutes read.

Vertical Order Traversal of Binary Tree

Implementation #include <iostream> #include <vector> #include <map> using namespace std; // representing the primary model of a binary tree node. struct _nod { int ky; _nod *Lft, *Rt; }; // establishing a new function representing the new binary tree node. struct _nod*...

5 minutes read.

Difference between Stack and Queue

In this article, we will learn about the major differences between Stack and Queue data structures. What is a stack? Stack – A stack is an abstract data structure defined as the...

3 minutes read.