判断三角形的类型
根据输入的三角形的三条边判断三角形的类型,并输出它的面积。
1 #include <stdio.h> 2 #include <math.h> 3 4 void judge_1(double x, double y, double z); 5 6 void main() 7 { 8 double a, b, c; 9 printf("输入三边 a b c: "); 10 scanf("%lf %lf %lf", &a, &b, &c); 11 judge_1(a, b, c); 12 printf("\n"); 13 } 14 15 void judge_1(double x, double y, double z) 16 { 17 double m, s, area; 18 if(x>y) 19 { 20 m = y; 21 y = x; 22 x = m; 23 } 24 if(x>z) 25 { 26 m = z; 27 z = x; 28 x = m; 29 } 30 if(y>z) 31 { 32 m = z; 33 z = y; 34 y = m; 35 } 36 37 if(x+y>z && z-y<x) 38 { 39 s = (x+y+z)/2.0; 40 area = sqrt(s*(s-x)*(s-y)*(s-z)); 41 if(x == y && x== z) 42 { 43 printf("等边三角形-面积为:%lf\n", area); 44 } 45 else if(x == y || y == z || x==z) 46 { 47 printf("等腰三角形-面积为:%lf\n", area); 48 } 49 else if(x*x + y*y == z*z) 50 { 51 printf("直角三角形-面积为:%lf\n", area); 52 } 53 else 54 { 55 printf("普通三角形-面积为:%lf\n", area); 56 } 57 } 58 else 59 { 60 printf("不能构成三角形\n"); 61 } 62 }