C语言学习10

时间:2022-01-17 06:37:37

判断三角形的类型

根据输入的三角形的三条边判断三角形的类型,并输出它的面积。

 #include <stdio.h>
#include <math.h> void judge_1(double x, double y, double z); void main()
{
double a, b, c;
printf("输入三边 a b c: ");
scanf("%lf %lf %lf", &a, &b, &c);
judge_1(a, b, c);
printf("\n");
} void judge_1(double x, double y, double z)
{
double m, s, area;
if(x>y)
{
m = y;
y = x;
x = m;
}
if(x>z)
{
m = z;
z = x;
x = m;
}
if(y>z)
{
m = z;
z = y;
y = m;
} if(x+y>z && z-y<x)
{
s = (x+y+z)/2.0;
area = sqrt(s*(s-x)*(s-y)*(s-z));
if(x == y && x== z)
{
printf("等边三角形-面积为:%lf\n", area);
}
else if(x == y || y == z || x==z)
{
printf("等腰三角形-面积为:%lf\n", area);
}
else if(x*x + y*y == z*z)
{
printf("直角三角形-面积为:%lf\n", area);
}
else
{
printf("普通三角形-面积为:%lf\n", area);
}
}
else
{
printf("不能构成三角形\n");
}
}