Encuentra la diagonal del cubo

Dado un lado del cubo a . La tarea es encontrar la longitud de la diagonal del cubo.
 

cube

Ejemplos: 
 

Entrada: a = 3 
Salida: 5,19615
Entrada: a = 6 
Salida: 10,3923 
 

Fórmula : 
 

Longitud de la diagonal del cubo = sqrt(3) * lado 

Prueba : 
 

Use el Teorema de Pitágoras, 
En el triángulo CED, 
CE 2 = CD 2 + DE 2 
l 2 = a 2 + a 2 ———>(1) 
En el triángulo CFE, 
CF 2 = CE 2 + EF 2 
L 2 = l 2 + a 2 
use el valor l 2 de la ecuación (1), 
L 2 = a 2 + a 2 + a 2 
= 3*a 2 
L = sqrt (3) * a
 

C++

// CPP program to find length
// of the diagonal of the cube
#include <bits/stdc++.h>
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

<?php
// PHP program to find length
// of the diagonal of the cube
 
// Function to find length
// of diagonal of cube
function diagonal_length($a)
{
    $L;
 
    // Formula to Find length
    // of diagonal of cube
    $L = $a * sqrt(3);
 
    return $L;
}
 
// Driver code
$a = 5;
 
// Function call
echo diagonal_length($a);
 
// This code is contributed
// by Naman_Garg.
?>

Javascript

<script>
// javascript program to find length
// of the diagonal of the cube
 
// Function to find length
// of diagonal of cube
function diagonal_length( a)
{
    let L;
 
    // Formula to Find length
    // of diagonal of cube
    L = a * Math.sqrt(3);
 
    return L;
}
 
// Driver code
    let a = 5;
 
    // Function call
    document.write(diagonal_length(a).toFixed(5));
     
// This code is contributed by gauravrajput1
</script>
Producción: 

8.66025

 

Publicación traducida automáticamente

Artículo escrito por nidhiva y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *