📌  相关文章
📜  可以内接在等边三角形内的最大六角形

📅  最后修改于: 2021-05-31 22:13:28             🧑  作者: Mango

给定边长为a的等边三角形,任务是找到可以内切的最大六边形。
例子:

方法:从图中可以看出,三个小三角形也是等边的。因此它们的边长为b = a / 3 ,其中b也是六边形的长度, a是给定等边三角形的长度。
下面是上述方法的实现:

C++
// C++ program to find the side of the
// largest hexagon which can be inscribed
// within an equilateral triangle
#include 
using namespace std;
 
// Function to find the side
// of the hexagon
float hexagonside(float a)
{
 
    // Side cannot be negative
    if (a < 0)
        return -1;
 
    // Side of the hexagon
    float x = a / 3;
    return x;
}
 
// Driver code
int main()
{
    float a = 6;
    cout << hexagonside(a) << endl;
    return 0;
}


Java
// Java program to find the side of the
// largest hexagon which can be inscribed
// within an equilateral triangle
class CLG
{
// Function to find the side
// of the hexagon
 static float hexagonside(float a)
{
 
    // Side cannot be negative
    if (a < 0)
        return -1;
 
    // Side of the hexagon
    float x = a / 3;
    return x;
}
 
// Driver code
public static void main(String[] args)
{
    float a = 6;
    System.out.println(hexagonside(a));
     
}
}


Python3
# Python3 program to find the side of the
# largest hexagon which can be inscribed
# within an eqilateral triangle
 
# function to find the side of the hexagon
def hexagonside(a):
     
    # Side cannot be negative
    if a < 0:
        return -1
         
    # Side of the hexagon
    x = a // 3
    return x
 
# Driver code
a = 6
print(hexagonside(a))
 
# This code is contributed
# by Mohit kumar 29


C#
using System;
// C# program to find the side of the
// largest hexagon which can be inscribed
// within an equilateral triangle
class CLG
{
// Function to find the side
// of the hexagon
 static float hexagonside(float a)
{
  
    // Side cannot be negative
    if (a < 0)
        return -1;
  
    // Side of the hexagon
    float x = a / 3;
    return x;
}
  
// Driver code
public static void Main()
{
    float a = 6;
    Console.Write(hexagonside(a));
      
}
}


PHP


Javascript


输出:
2