Program To Check whether a Triangle is Equilateral, Isosceles or Scalene
Equilateral Triangle: A triangle is said to be equilateral triangle if all the sides are equal. If X, Y, Z are three sides of the triangle. Then, the triangle is equilateral only if X = Y = Z.
Attention reader! All those who say programming isn't for kids, just haven't met the right mentors yet. Join the Demo Class for First Step to Coding Course, specifically designed for students of class 8 to 12.
The students will get to learn more about the world of programming in these free classes which will definitely help them in making a wise career choice in the future.
Isosceles Triangle: A triangle is said to be an isosceles triangle if any of its two sides are equal. If X, Y, Z are three sides of the triangle.Then, the triangle is isosceles if either X = Y or X = Z or Y = Z.
Scalene Triangle: A triangle is said Scalene Triangle if none of its sides is equal.
Input: X = 6, Y = 8, Z = 10
Output: Scalene Triangle
Since all the sides of the given triangle are unequal, the triangle is scalene.
Input: X = 10, Y = 10, Z = 10
Output: Equilateral Triangle
Since all the sides of the given triangle are equal.
Approach: Follow the steps below to solve the problem:
- Check if X = Y and Y = Z. If found to be true, print “Equilateral Triangle”.
- If it is not an Equilateral triangle, then check if X = Y or X = Z or Y = Z. If found to be true, print “Isosceles Triangle”.
- If none of the above steps are satisfied, then print “Scalene Triangle”.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)