Given a circle with radius ‘r’ is given, the task is to find the diameter or longest chord of the circle.
Input: r = 4 Output: 8 Input: r = 9 Output: 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
- 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:
The length of the longest chord or diameter of the circle is 8
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.