C Program to check whether the triangle is equilateral, isosceles or scalene



Triangle consists of three sides and three angles. Based on the three sides, there are three types of triangle −

  • Equilateral triangle: All three sides are equal.
  • Isosceles triangle: All two sides are equal.
  • Scalene triangle: No sides are equal.

Follow the algorithm given below for writing the respective program.

Algorithm

Step 1: Declare three sides of triangle.
Step 2: Enter three sides at run time.
Step 3: If side1 == side2 && side2 == side3
Go to step 6
Step 4: If side1 == side2 || side2 == side3 || side3 == side1
Go to Step 7
Step 5: Else
Go to step 8
Step 6: Print the triangle is equilateral.
Step 7: Print the triangle is isosceles.
Step 8: Print the triangle is scalene.

Program

Following is the C program to check whether the triangle is equilateral, isosceles or scalene −

 Live Demo

#include<stdio.h>
int main(){
   int side1, side2, side3;
   printf("Enter sides of triangle:");
   scanf("%d%d%d",&side1,&side2,&side3);
   if(side1 == side2 && side2 == side3)
      printf("The Given Triangle is equilateral
");    else if(side1 == side2 || side2 == side3 || side3 == side1)       printf("The given Triangle is isosceles
");    else       printf("The given Triangle is scalene
");    return 0; }

Output

Let us compile and run the above program that will produce the following result −

Run1:
Enter sides of triangle:3 4 6
The given Triangle is scalene
Run2 :
Enter sides of triangle:2 2 5
The given Triangle is isosceles
Run 3:
Enter sides of triangle:5 5 5
The Given Triangle is equilateral

Advertisements