用C++写出输入三角形三条边a、b、c,判断该三角形是什么三角形
时间: 2023-11-03 21:32:11 浏览: 156
根据输入三角形三条边判断该三角形形状
#include <stdio.h>
int main() {
float a, b, c;
printf("Enter the three sides of the triangle:\n");
scanf("%f%f%f", &a, &b, &c);
if (a <= 0 || b <= 0 || c <= 0) {
printf("Invalid input.\n");
} else if (a + b <= c || a + c <= b || b + c <= a) {
printf("Not a triangle.\n");
} else if (a == b && b == c) {
printf("Equilateral triangle.\n");
} else if (a == b || b == c || a == c) {
printf("Isosceles triangle.\n");
} else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a) {
printf("Right triangle.\n");
} else {
printf("Scalene triangle.\n");
}
return 0;
}
阅读全文