# Find the type of triangle from the given sides

Given three integers **A**, **B**, and **C** which denotes the sides of a triangle, the task is to check that the triangle is a right-angled, acute-angled or obtuse-angled triangle.

**Examples:**

Input:A = 1, B = 4, C = 3

Output:Obtuse-angled Triangle

Explanation:

Triangle with the sides 1, 2 and 3 is an obtuse-angled triangle

Input:A = 2, B = 2, C = 2

Output:Acute-angled Triangle

Explanation:

Triangle with the sides 2, 2, and 2 is an acute-angled triangle

**Approach:** The idea is to use the facts from the cosine law to check the type of triangle using this formulae –

It generalizes the Pythagorean Theorum, which states that for a right-angled triangle square of the hypotenuse is equal to the sum of squares of the base and height of the triangle, which is

Similarly, It can be observed that

For acute-angled triangle

For Obtuse-angled triangle

Below is the implementation of the above approach:

## 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 == sqa + sqb || ` ` ` `sqb == sqa + sqc || ` ` ` `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; ` `} ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

**Output:**

Acute-angled Triangle

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Find other two sides of a right angle triangle
- Find other two sides and angles of a right angle triangle
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Find area of triangle if two vectors of two adjacent sides are given
- Program to find the Type of Triangle from the given Coordinates
- Find the length of the median of a Triangle if length of sides are given
- Check whether triangle is valid or not if sides are given
- Check whether right angled triangle is valid or not for large sides
- Length of remaining two sides of a Triangle from a given side and its adjacent angles
- Probability of cutting a rope into three pieces such that the sides form a triangle
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Find area of parallelogram if vectors of two adjacent sides are given
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Find all angles of a triangle in 3D
- Find the Nth row in Pascal's Triangle
- Find all angles of a given triangle
- Find Perimeter of a triangle
- Program to find the Centroid of the triangle

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.