C program to check triangle is equilateral, isosceles or scalene

In this program, take three sides of a triangle as input from the user and check whether the triangle is equilateral, isosceles, or scalene.

check triangle is equilateral, isosceles or scalene

#include <stdio.h>
int main()
{
  int s1,s2,s3;
  printf("\n enter three side of tringle:");
  scanf("%d%d%d",&s1,&s2,&s3);
   if((s1==s2)&&(s2==s3))
   {
       /* if all side are equal */
       printf("\n tringle is equilateral");
   }
   else if((s1==s2)||(s2==s3)||(s1==s3))
   {
       /* if two side are equal */
       printf("\n tringle is isosceles");
   }
   else
   {
       /* if all side are diffrent */
       printf("\n tringle is scalene");
   }
   return 0;
}

output

Run:1
enter three side of tringle:10 10 10
tringle is equilateral
Run:2
enter three side of tringle:10 20 10
tringle is isosceles
Run:3
enter three side of tringle:10 20 30
tringle is scalene

Logic to check whether the triangle is equilateral, isosceles, or scalene

  • Take three sides of the triangle and store and stored the side in s1, s2, and s3.
  • First, you need to check whether all sides are equal or not i.e (s1 == s2) && (s2 == s3). if side s1 is equal to side s2 and side s2 is equal to side s3 then the triangle is equilateral.
  • If all sides are not equal then control flow transfer else if part. in else if part, you will check whether any two sides are equal or not i.e (s1 == s2) || (s2 == s3) || (s1 == s3). if any two sides are equal then the triangle is isosceles.
  • Now if any two sides are not equal then else part will get executed and the triangle is scalene.