luc019.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 12 Dec 2025
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
If the length of three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is an isosceles, an equilateral, a scalene or a right-angled triangle.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <math.h>
#define EPSILON 0.000001
/* EPSILON is used to compare double values for approximate equality,
mitigating floating-point precision errors. */
int main()
{
double side1, side2, side3;
printf("Please enter the length of three side of the triangle : ");
scanf("%lf %lf %lf", &side1, &side2, &side3);
if (side1 < 1 || side2 < 1 || side3 < 1)
{
printf("\nLength of a side of triangle should be a positive integer.");
return 1;
}
if (side1 + side2 < side3 || side1 + side3 < side2 || side2 + side3 < side1)
{
printf("\nEntered triangle is not VALID.");
return 1;
}
// isosceles check
if (side1 == side2 || side2 == side3 || side3 == side1)
printf("\nEntered triangle is a ISOSCELES triangle.");
else
printf("\nEntered triangle is NOT a ISOSCELES triangle.");
// equilateral check
if (side1 == side2 && side2 == side3)
printf("\nEntered triangle is a EQUILATERAL triangle.");
else
printf("\nEntered triangle is NOT a EQUILATERAL triangle.");
// scalene check
if (side1 != side2 && side2 != side3)
printf("\nEntered triangle is a SCALENE triangle.");
else
printf("\nEntered triangle is NOT a SCALENE triangle.");
// right-angle check
if (fabs(((side1 * side1) + (side2 * side2)) - (side3 * side3)) < EPSILON ||
fabs(((side2 * side2) + (side3 * side3)) - (side1 * side1)) < EPSILON ||
fabs(((side3 * side3) + (side1 * side1)) - (side2 * side2)) < EPSILON)
printf("\nEntered triangle is a RIGHT-ANGLED triangle.");
else
printf("\nEntered triangle is NOT a RIGHT-ANGLED triangle.");
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46