How to check the type of triangle using C

C Programming

C Program to check the type of triangle


#include <stdio.h>
#include <math.h>
 
int main() {
   int side1, side2, side3;
 
   //Change values accordingly
   side1 = 5;
   side2 = 4;
   side3 = 3;
 
   if ((side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1)
         && (side1 > 0 && side2 > 0 && side3 > 0)) {
      if (side1 == side2 && side2 == side3) {
         printf("Equilateral Triangle");
      } else if (side1 == side2 || side2 == side3 || side1 == side3) {
         printf("Isosceles Triangle");
      } else {
         printf("Scalene Triangle");
      }
   } else {
      printf("Triangle formation not possible");
   }
 
   return 0;
}

Output :


Enter the values of sides : 3 3 2
Isosceles Triangle
How to check the type of triangle using C
Updated on 12-Dec-2021 17:04:29

Advertisements