# Find the Diameter or Longest chord of a Circle

Given a circle with radius ‘r’ is given, the task is to find the diameter or longest chord of the circle.

**Examples:**

Input:r = 4Output:8Input:r = 9Output:18

**Proof that the Longest chord of a circle is its Diameter:**

- Draw circle O and any chord AB on it.
- From one endpoint of the chord, say A, draw a line segment through the centre. That is, draw a diameter.
- Now draw a radius from centre O to B.
- By the triangle inequality,
AB < AO + OB = r + r = 2r = d

- So, any chord that is not a diameter will be smaller than a diameter.
- So the largest chord is a diameter

**Approach**:

- The Longest chord of any circle is its diameter.
- Therefore, the diameter of a circle is twice the radius of it.
**Length of the longest chord or diameter = 2r**

Below is the implementation of the above approach:

## C++

`// C++ program to find ` `// the longest chord or diameter ` `// of the circle whose radius is given ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the longest chord ` `void` `diameter(` `double` `r) ` `{ ` ` ` `cout << ` `"The length of the longest chord"` ` ` `<< ` `" or diameter of the circle is "` ` ` `<< 2 * r << endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` ` ` `// Get the radius ` ` ` `double` `r = 4; ` ` ` ` ` `// Find the diameter ` ` ` `diameter(r); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find ` `// the longest chord or diameter ` `// of the circle whose radius is given ` `class` `GFG ` `{ ` ` ` `// Function to find the longest chord ` `static` `void` `diameter(` `double` `r) ` `{ ` ` ` `System.out.println(` `"The length of the longest chord"` ` ` `+ ` `" or diameter of the circle is "` ` ` `+ ` `2` `* r); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` ` ` `// Get the radius ` ` ` `double` `r = ` `4` `; ` ` ` ` ` `// Find the diameter ` ` ` `diameter(r); ` `} ` `} ` ` ` `// This code contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find ` `# the longest chord or diameter ` `# of the circle whose radius is given ` ` ` `# Function to find the longest chord ` `def` `diameter(r): ` ` ` ` ` `print` `(` `"The length of the longest chord"` ` ` `,` `" or diameter of the circle is "` ` ` `,` `2` `*` `r) ` ` ` ` ` `# Driver code ` ` ` `# Get the radius ` `r ` `=` `4` ` ` `# Find the diameter ` `diameter(r) ` ` ` `# This code is contributed by mohit kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find ` `// the longest chord or diameter ` `// of the circle whose radius is given ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the longest chord ` `static` `void` `diameter(` `double` `r) ` `{ ` ` ` `Console.WriteLine(` `"The length of the longest chord"` ` ` `+ ` `" or diameter of the circle is "` ` ` `+ 2 * r); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` ` ` `// Get the radius ` ` ` `double` `r = 4; ` ` ` ` ` `// Find the diameter ` ` ` `diameter(r); ` `} ` `} ` ` ` `// This code has been contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find ` `// the longest chord or diameter ` `// of the circle whose radius is given ` ` ` `// Function to find the longest chord ` `function` `diameter(` `$r` `) ` `{ ` ` ` `echo` `"The length of the longest chord"` ` ` `,` `" or diameter of the circle is "` ` ` `,2 * ` `$r` `<< ` `"\n"` `; ` `} ` ` ` ` ` `// Driver code ` ` ` `// Get the radius ` ` ` `$r` `= 4; ` ` ` ` ` `// Find the diameter ` ` ` `diameter(` `$r` `); ` ` ` ` ` `// This code is contributed by Ryuga ` ` ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

The length of the longest chord or diameter of the circle is 8

## Recommended Posts:

- Length of the chord the circle if length of the another chord which is equally inclined through the diameter is given
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is 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
- Find the other-end coordinates of diameter in a circle
- Find the center of the circle using endpoints of diameter
- Shortest distance from the centre of a circle to a chord
- Count ways to divide circle using N non-intersecting chord | Set-2
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Distance of chord from center when distance between center and another equal length chord is given
- Angle subtended by the chord when the angle subtended by another chord of same length is given
- Program to find Circumference of a Circle
- Program to find area of a circle
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Find if a point lies inside 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.