Last Updated: June 7, 2026
The problem has two layers. First confirm there is a triangle at all. Three lengths that violate the triangle inequality do not form a shape, so they get the label "Invalid" and never reach the classification step.
Once validity is settled, classification depends only on how many sides are equal. All three equal is equilateral, exactly two equal is isosceles, and none equal is scalene. The order of the checks matters: an equilateral triangle also has two equal sides, so test for all-three-equal first, or it gets mislabeled as isosceles.
"Invalid" regardless of which sides match.The triangle inequality is the concrete validity test: each pair of sides must sum to strictly more than the third. If any pair fails, return "Invalid" and stop.
For valid lengths, check equalities from most specific to least specific. All three equal is equilateral. Not all three but at least one pair equal is isosceles. No pair equal is scalene. This ordering keeps the equilateral case out of the isosceles branch.
"Invalid".a, b, and c are all equal, return "Equilateral"."Isosceles"."Scalene".Input:
The sides are 5, 5, and 8. First check validity: 5 + 5 > 8 gives 10 > 8 which is true, 5 + 8 > 5 is true, and 5 + 8 > 5 is true, so the lengths form a real triangle. Now classify. Are all three equal? No, since 8 differs from 5. Are any two equal? Yes, a and b are both 5. That makes exactly two sides equal, so the triangle is isosceles.