📜  可以在正方形内切出的最大六边形

📅  最后修改于: 2021-06-01 01:13:33             🧑  作者: Mango

给定正方形a的边,任务是找到可以在给定正方形内切入的最大六边形的边。
例子:

方法::假设六边形的边为x并假设正方形的边a被划分为较小的长度b和较大的长度c,a = b + c
现在从图中我们看到,

下面是上述方法的实现:

C++
// C++ Program to find the biggest hexagon which
// can be inscribed within the given square
#include 
using namespace std;
 
// Function to return the side
// of the hexagon
float hexagonside(float a)
{
 
    // Side cannot be negative
    if (a < 0)
        return -1;
 
    // Side of the hexagon
    float x = 0.5176 * a;
    return x;
}
 
// Driver code
int main()
{
    float a = 6;
    cout << hexagonside(a) << endl;
    return 0;
}


Java
// Java  Program to find the biggest hexagon which
// can be inscribed within the given square
 
import java.io.*;
 
class GFG {
     
// Function to return the side
// of the hexagon
static double hexagonside(double a)
{
 
    // Side cannot be negative
    if (a < 0)
        return -1;
 
    // Side of the hexagon
    double x = (0.5176 * a);
    return x;
}
 
// Driver code
    public static void main (String[] args) {
 
        double a = 6;
        System.out.println (hexagonside(a));
    }
//This code is contributed by ajit.   
}


Python 3
# Python 3 Program to find the biggest
# hexagon which can be inscribed within
# the given square
 
# Function to return the side
# of the hexagon
def hexagonside(a):
 
    # Side cannot be negative
    if (a < 0):
        return -1;
 
    # Side of the hexagon
    x = 0.5176 * a;
    return x;
 
# Driver code
a = 6;
print(hexagonside(a));
 
# This code is contributed
# by Akanksha Rai


C#
// C# Program to find the biggest hexagon which
// can be inscribed within the given square
using System;
 
class GFG
{
         
// Function to return the side
// of the hexagon
static double hexagonside(double a)
{
 
    // Side cannot be negative
    if (a < 0)
        return -1;
 
    // Side of the hexagon
    double x = (0.5176 * a);
    return x;
}
 
// Driver code
public static void Main ()
{
    double a = 6;
    Console.WriteLine(hexagonside(a));
}
}
 
// This code is contributed by Ryuga.


PHP


Javascript


输出:
3.1056