Write A C++ Program To Find Triangle Is Equilateral, Isosceles, Right angled Or Scalene. Before writing the code we must know what is Equilateral or what is Isosceles, what is Right angled what is Scalene Triangle. As we all know that triangles have 3 sides. So based on the sides we can identify the type of triangle.
Type of Triangles
Below are the 4 types of triangles.
1. Equilateral Triangle
An equilateral triangle is a triangle in which all three sides have the same length. In the familiar Euclidean geometry, an equilateral triangle is also equiangular; that is, all three internal angles are also congruent to each other and are each 60°.
If all the side (A, B, C) of the Triangle is equal means if A = B = C then the triangle is Equilateral Triangle.
2. Isosceles Triangle
An isosceles triangle is a triangle that has two sides of equal length. Sometimes it is specified as having exactly two sides of equal length, and sometimes as having at least two sides of equal length, the latter version thus including the equilateral triangle as a special case.
If two sides of a Triangle Is Equal In length means if A = B or B = C or C = A then the triangle is Isosceles Triangle.
3. Right-Angled Triangle
Right-angled triangles are those triangles in which one angle is 90 degrees. Since one angle is 90°, the sum of the other two angles will be 90°.
To be a right angle means a*a == b*b + c*c or b*b == c*c + a*a or c*c == a*a + b*b any one of the Conditions is true then it is Right angled Triangle.
4. Scalene Triangle
A scalene triangle can be defined as a triangle whose all three sides have different lengths, and all three angles are of different measures. The angles of a scalene triangle follow the angle sum property and always add up to 180.
If all Sides are Unequal Then It is Scalene Triangle.
C++ Program to Check Triangle Is Right-Angled, Equilateral, Isosceles or Scalene
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter The Value of a, b, c \n";
cin>>a>>b>>c;
if(a==b && b==c && c==a)
{
cout<<"The Triangle is Equilateral Triangle\n");
}
else if(a==b || b==c || c==a)
{
cout<<"The Triangle is Isosceles Triangle\n");
}
else if(a*a==b*b+c*c ||b*b==c*c+a*a || c*c==a*a+b*b)
{
cout<<"The Triangle is Right Triangle\n");
}
else
{
cout<<"The Triangle Scalene Triangle\n");
}
return 0;
}
Triangle Is Equilateral Isosceles Right angled Or Scalene Program Output in C++
0 Comments: