Triangle Type
Completed
Read three side lengths. Print invalid, equilateral, isosceles or scalene.
Input
Three positive integers.
Output
One word.
Example
Input
3 3 3
Output
equilateral
Editor
C
Hints
Any side must be shorter than the sum of the other two.
Solution explanation
Checking validity first means the later branches only see real triangles.
Show solution
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a + b <= c || a + c <= b || b + c <= a) {
printf("invalid\n");
} else if (a == b && b == c) {
printf("equilateral\n");
} else if (a == b || b == c || a == c) {
printf("isosceles\n");
} else {
printf("scalene\n");
}
return 0;
}