Given here are **n** circles which touch each other externally, and are lined up in a row. The distance between the centers of the first and last circle is given. The circles have a radius of equal length. The task is to find the radius of each circle.

**Examples:**

Input:d = 42, n = 4Output:The radius of each circle is 7Input:d = 64, n = 5Output:The radius of each circle is 8

**Approach**:

Suppose there are **n** circles each having radius of length **r**.

Let, the distance between the first and last circles = **d**

From the figure, it is clear,

**r + r + (n-2)*2r = d
2r + 2nr – 4r = d
2nr – 2r = d**

so,

**r = d/(2n-2)**

## C++

`// C++ program to find radii of the circles ` `// which are lined in a row ` `// and distance between the ` `// centers of first and last circle is given ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `void` `radius(` `int` `n, ` `int` `d) ` `{ ` ` ` `cout << ` `"The radius of each circle is "` ` ` `<< d / (2 * n - 2) << endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `d = 42, n = 4; ` ` ` `radius(n, d); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find radii of the circles ` `// which are lined in a row ` `// and distance between the ` `// centers of first and last circle is given ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `static` `void` `radius(` `int` `n, ` `int` `d) ` `{ ` ` ` `System.out.print( ` `"The radius of each circle is "` ` ` `+d / (` `2` `* n - ` `2` `)); ` `} ` ` ` `// Driver code ` `static` `public` `void` `main (String []args) ` `{ ` ` ` `int` `d = ` `42` `, n = ` `4` `; ` ` ` `radius(n, d); ` `} ` `} ` ` ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

## Python3

`# Python program to find radii of the circles ` `# which are lined in a row ` `# and distance between the ` `# centers of first and last circle is given ` ` ` `def` `radius(n, d): ` ` ` `print` `(` `"The radius of each circle is "` `, ` ` ` `d ` `/` `(` `2` `*` `n ` `-` `2` `)); ` ` ` `d ` `=` `42` `; n ` `=` `4` `; ` `radius(n, d); ` ` ` ` ` `# This code is contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find radii of the circles ` `// which are lined in a row ` `// and distance between the ` `// centers of first and last circle is given ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `static` `void` `radius(` `int` `n, ` `int` `d) ` `{ ` ` ` `Console.Write( ` `"The radius of each circle is "` ` ` `+d / (2 * n - 2)); ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main () ` `{ ` ` ` `int` `d = 42, n = 4; ` ` ` `radius(n, d); ` `} ` `} ` ` ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

**Output:**

The radius of each circle is 7

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find the side of the squares which are lined in a row, and distance between the centers of first and last square is given
- Distance between centers of two intersecting circles if the radii and common chord length is given
- Ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles
- Ratio of the distance between the centers of the circles and the point of intersection of two transverse common tangents to the circles
- Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius
- Find the side of the squares which are inclined diagonally and lined in a row
- Number of common tangents between two circles if their centers and radius is given
- Length of the perpendicular bisector of the line joining the centers of two circles
- Check whether given circle resides in boundary maintained by two other circles
- Check if a given circle lies completely inside the ring formed by two concentric circles
- Radius of the inscribed circle within three tangent circles
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Maximum possible intersection by moving centers of line segments
- Check whether it is possible to join two points given on circle such that distance between them is k
- Distance of chord from center when distance between center and another equal length chord is given
- Calculate Stirling numbers which represents the number of ways to arrange r objects around n different circles
- Equation of circle when three points on the circle are given
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Shortest distance between a point and a circle

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.