In this program, take three sides of a triangle as input from the user and check whether the 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;
}
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
s1
, s2
, and s3
.(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
.(s1 == s2) || (s2 == s3) || (s1 == s3)
. if any two sides are equal then the triangle is isosceles
.scalene
.