📜  查找圆的直径或最长和弦

📅  最后修改于: 2021-05-04 21:18:33             🧑  作者: Mango

给定半径为“ r”的圆,任务是找到圆的直径或最长弦。
例子:

Input: r = 4
Output: 8

Input: r = 9
Output: 18

证明圆的最长弦是其直径:

  • 在其上绘制圆O和任何和弦AB。
  • 从和弦的一个端点(例如A)在中心画一条线段。即画一个直径。
  • 现在从中心O到B绘制一个半径。
  • 通过三角形不等式,
AB < AO + OB
 = r + r
 = 2r
 = d
  • 因此,任何非直径的和弦都将小于直径。
  • 所以最大的弦是直径

方法

  • 任何圆圈的最长弦是其直径。
  • 因此,圆的直径是其半径的两倍。
Length of the longest chord or diameter = 2r

下面是上述方法的实现:

C++
// C++ program to find
// the longest chord or diameter
// of the circle whose radius is given
 
#include 
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;
}


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


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


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


PHP


Javascript


输出:
The length of the longest chord or diameter of the circle is 8