I think I am trapped with if
/else if
statements. Program to define what the type of the triangle is.
I don't understand, why it doesn't work properly. And, if it wouldn't be difficult, can you show how to optimize the work of right-angled triangle, using the Pythagorean theorem? In order to not mix the right-angled triangle with other triangles.
Code:
int main() {
int a = 3;
int b = 4;
int c = 5;
int angle_A = 100;
int angle_B = 10;
int angle_C = 70;
if (a == b && a == c && c == b) {
printf("Equilateral triangle\n");
}
else if (a == c || b == c || a == b) {
printf("isosceles triangle.\n");
}
if ((pow(c, 2) == pow(b, 2) + pow(a, 2)) || (pow(a, 2) == pow(b, 2) || pow(c, 2)) || (pow(b, 2) == pow(c, 2) + pow(a, 2))) {
printf("right-angled triangle.\n");
}
if ((angle_A < 90 || angle_B < 90 || angle_C < 90) && angle_A + angle_B + angle_C == 180) {
printf("acute-angled triagle.\n");
}
if ((angle_A > 90 || angle_B > 90 || angle_C > 90) && angle_A + angle_B + angle_C == 180) {
printf("An obtuse triangle.\n");
}
return 0;
}
The output of this code:
right-angled triangle.
acute-angled triangle.
An obtuse triangle.