📌  相关文章
📜  从给定的边找到三角形的类型

📅  最后修改于: 2021-05-20 06:52:55             🧑  作者: Mango

给定表示三角形边的三个整数ABC ,任务是检查该三角形是直角三角形,锐角三角形还是钝角三角形。

例子:

方法:想法是使用余弦定律的事实,使用以下公式来检查三角形的类型–
 c^2 &= a^2 + b^2 - 2*a*b*cos\gamma
它推广了勾股定理,该定理指出斜边直角三角形的平方等于三角形的底边和高度的平方和。 c^2 &= a^2 + b^2

同样,可以观察到
对于锐角三角形
c^2 \textless a^2 + b^2
对于钝角三角形
c^2 \textgreater a^2 + b^2

下面是上述方法的实现:

C++
// C++ implementation to find
// the type of triangle with
// the help of the sides
  
#include 
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


输出:
Acute-angled Triangle