📜  找到立方体的对角线

📅  最后修改于: 2021-05-04 20:20:01             🧑  作者: Mango

给定立方体一侧。任务是找到立方体对角线的长度。

立方体

例子:

公式 :

证明 :

C++
// CPP program to find length
// of the diagonal of the cube
#include 
using namespace std;
 
// Function to find length
// of diagonal of cube
float diagonal_length(float a)
{
    float L;
 
    // Formula to Find length
    // of diagonal of cube
    L = a * sqrt(3);
 
    return L;
}
 
// Driver code
int main()
{
 
    float a = 5;
 
    // Function call
    cout << diagonal_length(a);
 
    return 0;
}


Java
// Java program to find length
// of the diagonal of the cube
class GFG
{
     
    // Function to find length
    // of diagonal of cube
    static float diagonal_length(float a)
    {
        float L;
         
        // Formula to Find length
        // of diagonal of cube
        L = a * (float)Math.sqrt(3);
         
        return L;
    }
     
    // Driver Code
    public static void main (String[] args)
    {
        float a = 5;
         
        // Function call
        System.out.println(diagonal_length(a));
    }
}
 
// This code is contributed by
// sanjeev2552


Python3
# Python3 program to find length
# of the diagonal of the cube
from math import sqrt
 
# Function to find length
# of diagonal of cube
def diagonal_length(a):
    L = 0
 
    # Formula to Find length
    # of diagonal of cube
    L = a * sqrt(3)
 
    return L
 
# Driver code
a = 5
 
# Function call
print(diagonal_length(a))
 
# This code is contributed by Mohit Kumar


C#
// C# program to find length
// of the diagonal of the cube
using System;
class GFG
{
// Function to find length
// of diagonal of cube
static float diagonal_length(float a)
{
    float L;
 
    // Formula to Find length
    // of diagonal of cube
    L = a * (float)Math.Sqrt(3);
 
    return L;
}
 
// Driver code
public static void Main()
{
    float a = 5;
 
    // Function call
    Console.Write(diagonal_length(a));
}
}
 
// This code is contributed by Nidhi


PHP


Javascript


输出:
8.66025