Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Classify a Triangle Using Sides and Angles

Basic Acceptance 73.99% Points 10.00

You are given three sides of a valid triangle. Your task is to classify the triangle both by its sides and by its angles.

Classify the triangle by sides as Equilateral, Isosceles, or Scalene, based on the equality of its sides.

Classify the triangle by angles as Right, Acute, or Obtuse, using the relationship between the squares of the sides. Let the largest side be (c), and the other two sides be (a) and (b).

  • If (a2 + b2 = c^2), the triangle is Right.
  • If (a2 + b2 > c^2), the triangle is Acute.
  • If (a2 + b2 < c^2), the triangle is Obtuse.
Examples
Example 1

image Input: a = 3, b = 4, c = 5
Output: Scalene, Right
Explanation: No sides are equal, and 3² + 4² = 5², forming a right triangle.

Example 2

image Input: a = 5, b = 5, c = 5
Output: Equilateral, Acute
Explanation: All sides are equal, and every angle is 60°, making the triangle acute.

Example 3

image Input: a = 5, b = 5, c = 9
Output: Isosceles, Obtuse
Explanation: Two sides are equal, and 9² > 5² + 5², so the triangle is obtuse.

Constraints
  • 0 < each side = 104
  • The sides form a valid triangle.
Companies
Amazon Apple
Topics
Data Structures Basics Comparisons
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions