luc019.c (2164B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 12 Dec 2025 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* If the length of three sides of a triangle are entered through the 9 keyboard, write a program to check whether the triangle is an isosceles, 10 an equilateral, a scalene or a right-angled triangle. */ 11 /* Let Us C, Chap- 4, Page - 71, Qn No.: D(a) */ 12 13 #include <stdio.h> 14 #include <math.h> 15 16 #define EPSILON 0.000001 17 /* EPSILON is used to compare double values for approximate equality, 18 mitigating floating-point precision errors. */ 19 20 int main() 21 { 22 double side1, side2, side3; 23 printf("Please enter the length of three side of the triangle : "); 24 scanf("%lf %lf %lf", &side1, &side2, &side3); 25 if (side1 < 1 || side2 < 1 || side3 < 1) 26 { 27 printf("\nLength of a side of triangle should be a positive integer."); 28 return 1; 29 } 30 if (side1 + side2 < side3 || side1 + side3 < side2 || side2 + side3 < side1) 31 { 32 printf("\nEntered triangle is not VALID."); 33 return 1; 34 } 35 // isosceles check 36 if (side1 == side2 || side2 == side3 || side3 == side1) 37 printf("\nEntered triangle is a ISOSCELES triangle."); 38 else 39 printf("\nEntered triangle is NOT a ISOSCELES triangle."); 40 // equilateral check 41 if (side1 == side2 && side2 == side3) 42 printf("\nEntered triangle is a EQUILATERAL triangle."); 43 else 44 printf("\nEntered triangle is NOT a EQUILATERAL triangle."); 45 // scalene check 46 if (side1 != side2 && side2 != side3) 47 printf("\nEntered triangle is a SCALENE triangle."); 48 else 49 printf("\nEntered triangle is NOT a SCALENE triangle."); 50 // right-angle check 51 if (fabs(((side1 * side1) + (side2 * side2)) - (side3 * side3)) < EPSILON || 52 fabs(((side2 * side2) + (side3 * side3)) - (side1 * side1)) < EPSILON || 53 fabs(((side3 * side3) + (side1 * side1)) - (side2 * side2)) < EPSILON) 54 printf("\nEntered triangle is a RIGHT-ANGLED triangle."); 55 else 56 printf("\nEntered triangle is NOT a RIGHT-ANGLED triangle."); 57 return 0; 58 }