判断三角形的性质(直角或等腰)简便算法

it2025-03-18  14

学习目标:

判断三角形的性质(直角或等腰)简便算法


每日一练

题目

输入三角形的三条边a,b,c,判断它们能否构成三角形。若能构成三角形,指出是何种三角形(等腰三角形、直角三角形、一般三角形)。 (提示:判断a,b两边是否相等需要用fabs(a - b) <=1e-1这种格式,同理,判断勾股定理的精度也一样)

**输入格式要求:"%f,%f,%f" 提示信息:"Input the three edge length: " **输出格式要求:“等腰三角形” “直角三角形” “一般三角形” “不是三角形” 程序运行示例如下: ① Input the three edge:3,4,5↙ 直角三角形 ② Input the three edge:4,4,5↙ 等腰三角形 ③ Input the three edge:10,10,14.14↙ 等腰直角三角形 ④ Input the three edge:3,4,9↙ 不是三角形

示例:

#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { float a,b,c; printf("Input the three edge length: "); scanf("%f,%f,%f",&a,&b,&c); if(a+b>c&&a+c>b&&b+c>a) { if(fabs(a-b)<1e-1||fabs(c-b)<1e-1||fabs(a-c)<1e-1) { printf("等腰"); } if(a*a-b*b+c*c<1e-1||c*c+b*b-a*a<1e-1||a*a+b*b-c*c<1e-1) { printf("直角"); } printf("三角形"); } else { printf("不是三角形"); } return 0; } 先判断是否等腰三角形,再输出“等腰”两个字,再判断是否直角三角形,输出“直角”最后输出三角形可以简化判断的次数。
最新回复(0)