C : Check If A Triangle Is Equilateral, Isosceles Or Scalene - W3resource

C Exercises: Check whether a triangle is Equilateral, Isosceles or Scalene

Last update on July 29 2025 12:51:43 (UTC/GMT +8 hours)

14. Triangle Type Determination

Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene.

Equilateral triangle: An equilateral triangle is a triangle in which all three sides are equal. In the familiar Euclidean geometry, equilateral triangles are also equiangular; that is, all three internal angles are also congruent to each other and are each 60°.

Isosceles triangle: An isosceles triangle is a triangle that has two sides of equal length.

Scalene triangle: A scalene triangle is a triangle that has three unequal sides, such as those illustrated above.

Visual Presentation:

Accept a temperature in centigrade and display a suitable message

Sample Solution:

C Code:

#include <stdio.h> // Include the standard input/output header file. int main() { int sidea, sideb, sidec; // Declare variables for the sides of the triangle. /* * Reads all sides of a triangle */ printf("Input three sides of triangle: "); // Prompt user for input. scanf("%d %d %d", &sidea, &sideb, &sidec); // Read and store the sides of the triangle. // Check if the sides form a valid triangle if ((sidea + sideb > sidec) && (sidea + sidec > sideb) && (sideb + sidec > sidea)) { // If the sides form a valid triangle, continue with the classification if(sidea==sideb && sideb==sidec) // Check if all sides are equal. { printf("This is an equilateral triangle.\n"); // Print message for equilateral triangle. } else if(sidea==sideb || sidea==sidec || sideb==sidec) // Check if two sides are equal. { printf("This is an isosceles triangle.\n"); // Print message for isosceles triangle. } else // If no sides are equal. { printf("This is a scalene triangle.\n"); // Print message for scalene triangle. } } else { // If the sides do not form a valid triangle printf("Input sides do not form a valid triangle.\n"); } return 0; }

Output:

Input three sides of triangle: 50 50 60 This is an isosceles triangle.

Flowchart:

Flowchart: Check whether a triangle is Equilateral, Isosceles or Scalene.

For more Practice: Solve these Related Problems:

  • Write a C program to determine if a triangle is equilateral, isosceles, or scalene and check for triangle validity.
  • Write a C program to determine the triangle type based on three angles and validate that they sum to 180.
  • Write a C program to classify a triangle using side lengths and also determine if it is right-angled.
  • Write a C program to input triangle side lengths and output the triangle type along with its perimeter.

Go to:

  • C Conditional Statement Exercises Home ↩
  • C Programming Exercises Home ↩

PREV : Temperature-Based Weather Message. NEXT : Triangle Validity by Angles.

C Programming Code Editor:

Click to Open Editor

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Tag » Area Of Isosceles Triangle Code In C