- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# Check if a given circle lies completely inside the ring formed by two concentric circles in C++

We have two circles. The center of both of them is at the origin. The radius of these two circles is given. They are r and R, R > r. Another circle is also present. Its radius (r1) and the center point are given, we have to check whether that point is inside the ring formed by the first two circles or not.

We can solve this using the Pythagorean theorem. compute the distance from the center of the circle and origin. Then if (distance – r1) >= r and (distance – r1) <= R, if both are true, then the circle is inside the ring.

## Example

#include <iostream> #include <cmath> using namespace std; bool isInside(int r, int R, int r1, int x, int y) { int dis = sqrt(x*x+y*y); return (dis-r1 >= R && dis+r1 <= r); } int main() { int r = 8, R = 4, r1 = 2, x = 6, y = 0; if (isInside(r, R, r1, x, y)) cout << "Circle is inside the ring." << endl; else cout << "Circle is not inside the ring." << endl; }

## Output

Circle is inside the ring.

- Related Articles
- Check if a circle lies inside another circle or not in C++
- Check if a given point lies inside a Polygon
- If the circumferences of two concentric circles forming a ring are $88 \ cm$ and $66 \ cm$ respectively. then find the width of the ring.
- Check whether given circle resides in boundary maintained by two other circles in Python
- Find if a point lies inside a Circle in C++
- How To Check if a Given Point Lies Inside a Rectangle in Java?
- Check whether a given point lies inside a Triangle\n
- C++ Program to Check if a Point d lies inside or outside a circle defined by Points a, b, c in a Plane
- Check if a point lies on or inside a rectangle in Python
- Check if a given string can be formed by two other strings or their permutations
- Program to calculate the area between two Concentric Circles in C++?
- An archery target has three regions formed by three concentric circles as shown in the figure. If the diameters of the concentric circles are in the ratio 1:2:3, then find the ratio of the areas of three regions."\n
- Find the area enclosed between two concentric circles of radii 3.5 cm and 7 cm. A third concentric circle is drawn outside the 7 cm circle, such that the area enclosed between it and the 7 cm circle is same as that between the two inner circles. Find the radius of the third circle correct to one decimal place.
- Two concentric circles are of radii 5 cm and 3 cm. Find the length of the chord of the larger circle which touches the smaller circle.
- Draw two concentric circles of radii 3 cm and 5 cm. Construct a tangent to the smaller circle from a point on the larger circle. Also, measure its length.

Advertisements