In this blog, we create a program to check whether a triangle is right-angled or not.
What is a “Right angle triangle”?
Being a right angle means a*a==b*b+c*c Or b*b==c*c+a*a Or c*c==a*a+b*b either condition is true then it is A right triangle.
Algorithm to create the respective code
For a right triangle to be valid, it must meet the following criteria:
- a, b and c should be greater than 0.
- The sum of any two sides of a triangle must be greater than the third side.
- Pythagorean theorem, i.e. a^2 + b^2 = c^2.
C++ code to check whether a triangle is right angled or not
#include<iostream> using namespace std; int main() { int a,b,c; cout<<"Enter The Value Of a,b,c \n";//side's of triangle cin>>a>>b>>c; if(a*a==b*b+c*c ||b*b==c*c+a*a || c*c==a*a+b*b) { cout<<"The Triangle is Right angled\n"; } else { cout<<"The Triangle Scalene angled\n"; } return 0; }
Output of the above code
Explanation of the code
Since the values of side i.e. a,b, and c follows and satisfies the relation a^2 + b^2 = c^2 therefore, the result of the output shows that the triangle is a right-angled triangle.