Dados tres números enteros A , B y C que denotan los lados de un triángulo, la tarea es comprobar que el triángulo es un triángulo rectángulo, ángulo agudo u obtusángulo.
Ejemplos:
Entrada: A = 1, B = 4, C = 3
Salida: Triángulo obtusángulo
Explicación:
El triángulo con los lados 1, 2 y 3 es un triángulo obtusángulo
Entrada: A = 2, B = 2, C = 2
Salida : Triángulo de ángulo agudo
Explicación:
El triángulo con los lados 2, 2 y 2 es un triángulo de ángulo agudo
Enfoque: La idea es usar los hechos de la ley del coseno para verificar el tipo de triángulo usando estas fórmulas.
Generaliza el Teorema de Pitágoras , que establece que para un triángulo rectángulo, el cuadrado de la hipotenusa es igual a la suma de los cuadrados de la base y la altura del triángulo, que es
De manera similar, se puede observar que
Para un triángulo de ángulo agudo Para un triángulo
de ángulo obtuso
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ implementation to find // the type of triangle with // the help of the sides #include <bits/stdc++.h> using namespace std; // Function to find the type of // triangle with the help of sides void checkTypeOfTriangle(int a, int b, int c){ int sqa = pow(a, 2); int sqb = pow(b, 2); int sqc = pow(c, 2); if (sqa == sqb + sqc || sqb == sqc + sqa || sqc == sqa + sqb){ cout << "Right-angled Triangle"; } else if(sqa > sqc + sqb || sqb > sqa + sqc || sqc > sqa + sqb){ cout << "Obtuse-angled Triangle"; } else{ cout << "Acute-angled Triangle"; } } // Driver Code int main() { int a, b, c; a = 2; b = 2; c = 2; // Function Call checkTypeOfTriangle(a, b, c); return 0; }
Java
// Java implementation to find // the type of triangle with // the help of the sides import java.util.*; class GFG { // Function to find the type of // triangle with the help of sides static void checkTypeOfTriangle(int a, int b, int c){ int sqa = (int)Math.pow(a, 2); int sqb = (int)Math.pow(b, 2); int sqc = (int)Math.pow(c, 2); if (sqa == sqa + sqb || sqb == sqa + sqc || sqc == sqa + sqb){ System.out.print("Right-angled Triangle"); } else if(sqa > sqc + sqb || sqb > sqa + sqc || sqc > sqa + sqb){ System.out.print("Obtuse-angled Triangle"); } else{ System.out.print( "Acute-angled Triangle"); } } // Driver Code public static void main (String []args) { int a, b, c; a = 2; b = 2; c = 2; // Function Call checkTypeOfTriangle(a, b, c); } } // This code is contribute by chitranayal
Python3
# Python3 implementation to find # the type of triangle with # the help of the sides # Function to find the type of # triangle with the help of sides def checkTypeOfTriangle(a,b,c): sqa = pow(a, 2) sqb = pow(b, 2) sqc = pow(c, 2) if (sqa == sqa + sqb or sqb == sqa + sqc or sqc == sqa + sqb): print("Right-angled Triangle") elif(sqa > sqc + sqb or sqb > sqa + sqc or sqc > sqa + sqb): print("Obtuse-angled Triangle") else: print("Acute-angled Triangle") # Driver Code if __name__ == '__main__': a = 2 b = 2 c = 2 # Function Call checkTypeOfTriangle(a, b, c) # This code is contributed by mohit kumar 29
C#
// C# implementation to find // the type of triangle with // the help of the sides using System; class GFG { // Function to find the type of // triangle with the help of sides static void checkTypeOfTriangle(int a, int b, int c){ int sqa = (int)Math.Pow(a, 2); int sqb = (int)Math.Pow(b, 2); int sqc = (int)Math.Pow(c, 2); if (sqa == sqa + sqb || sqb == sqa + sqc || sqc == sqa + sqb){ Console.Write("Right-angled Triangle"); } else if(sqa > sqc + sqb || sqb > sqa + sqc || sqc > sqa + sqb){ Console.Write("Obtuse-angled Triangle"); } else{ Console.Write( "Acute-angled Triangle"); } } // Driver Code public static void Main(String []args) { int a, b, c; a = 2; b = 2; c = 2; // Function Call checkTypeOfTriangle(a, b, c); } } // This code is contributed by 29AjayKumar
Javascript
<script> // JavaScript implementation to find // the type of triangle with // the help of the sides // Function to find the type of // triangle with the help of sides function checkTypeOfTriangle(a,b,c) { let sqa = Math.floor(Math.pow(a, 2)); let sqb = Math.floor(Math.pow(b, 2)); let sqc = Math.floor(Math.pow(c, 2)); if (sqa == sqa + sqb || sqb == sqa + sqc || sqc == sqa + sqb){ document.write("Right-angled Triangle"); } else if(sqa > sqc + sqb || sqb > sqa + sqc || sqc > sqa + sqb){ document.write("Obtuse-angled Triangle"); } else{ document.write( "Acute-angled Triangle"); } } // Driver Code let a, b, c; a = 2; b = 2; c = 2; // Function Call checkTypeOfTriangle(a, b, c); // This code is contributed by rag2127 </script>
Acute-angled Triangle
Publicación traducida automáticamente
Artículo escrito por PratikLath y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA