Dado un entero a que es el lado de un decágono regular, la tarea es encontrar e imprimir la longitud de su diagonal.
Ejemplos:
Entrada: a = 5
Salida: 9.51
Entrada: a = 9
Salida: 17.118
Enfoque: Sabemos que la suma de los ángulos interiores de un polígono = (n – 2) * 180 donde, n es el no. de lados en el polígono.
Entonces, la suma de los ángulos interiores del decágono = 8 * 180 = 1440 y cada ángulo interior será 144 .
Ahora, tenemos que encontrar BC = 2 * x . Si dibujamos una perpendicular AO en BC , veremos que la perpendicular biseca a BC en BO y OC , ya que los triángulos AOB y AOC son congruentes entre sí.
Entonces, en el triángulo AOB ,sin(72) = x / a ie x = 0.951 * a
Por lo tanto, la longitud de la diagonal será 2 * x ie 1.902 * a .
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to find the diagonal // of a regular decagon #include <bits/stdc++.h> using namespace std; // Function to return the diagonal // of a regular decagon float decdiagonal(float a) { // Side cannot be negative if (a < 0) return -1; // Length of the diagonal float d = 1.902 * a; return d; } // Driver code int main() { float a = 9; cout << decdiagonal(a) << endl; return 0; }
Java
// Java program to find the diagonal of a regular decdiagonal import java.util.*; import java.lang.*; import java.io.*; public class GFG { // Function to return the diagonal of a regular decdiagonal static double decdiagonal(double a) { //side cannot be negative if(a<0) return -1; // length of the diagonal double d=1.902*a; return d; } // Driver code public static void main(String[] args) { int a = 9; System.out.println(decdiagonal(a)); } }
Python3
# Python3 program to find the diagonal # of a regular decagon # Function to return the diagonal # of a regular decagon def decdiagonal(a) : # Side cannot be negative if (a < 0) : return -1 # Length of the diagonal d = 1.902 * a return d # Driver code if __name__ == "__main__" : a = 9 print(decdiagonal(a)) # This code is contributed by Ryuga
C#
// C# program to find the diagonal of a regular decdiagonal using System; public class GFG { // Function to return the diagonal of a regular decdiagonal static double decdiagonal(double a) { //side cannot be negative if(a<0) return -1; // length of the diagonal double d=1.902*a; return d; } // Driver code public static void Main() { int a = 9; Console.WriteLine(decdiagonal(a)); } } // This code is contributed by anuj_67..
PHP
<?php // PHP program to find the diagonal // of a regular decagon // Function to return the diagonal // of a regular decagon function decdiagonal($a) { // Side cannot be negative if ($a < 0) return -1; // Length of the diagonal $d = 1.902 * $a; return $d; } // Driver code $a = 9; echo decdiagonal($a); // This code is contributed by ajit. ?>
Javascript
<script> // javascript program to find the diagonal of a regular decdiagonal // Function to return the diagonal of a regular decdiagonal function decdiagonal(a) { // side cannot be negative if(a < 0) return -1; // length of the diagonal var d = 1.902*a; return d; } // Driver code var a = 9; document.write(decdiagonal(a)); // This code contributed by Princi Singh </script>
17.118
Complejidad de tiempo: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA