任意输入三个数是否能构成三角形,若可以输出其类型并求出面积。(类型只分位一般三角形,等腰,等边) 求帮忙检查,谢谢了。
程序代码:
#include<stdio.h>
#include<math.h>
void main()
{
float a, b, c, s, x, y, z, p;
float max(float a, float b, float c);
float min(float a, float b, float c);
float mid(float a, float b, float c);
printf("请输入三边长 \n");
scanf_s("%f,%f,%f", &a, &b, &c);
p = a + b + c / 2;
s = sqrt(p*(p - a)*(p - b)*(p - c));
x = max(a, b, c);
y = mid(a, b, c);
z = min(a, b, c);
if (a < 0 || b < 0 || c < 0)printf("输入错误\n");
else if (z + y <= x)printf("三边不能构成三角形\n");
else if (z == y&&y == x)printf("等边三角形,面积为%4.2f\n", s);
else if (z = y&&y != x)printf("等腰三角形,面积为%4.2f\n", s);
else printf("一般三角形,面积为%4.2f", s);
}
float max(float a, float b, float c)
{
float z,p;
if (a > b)p = a;
else p = b;
if (p > c)z = p;
else z = c;
return(z);
}
float min(float a, float b, float c)
{
float z, p;
if (a < b)p = a;
else p = b;
if (p < c)z = p;
else z = c;
return(z);
}
float mid(float a, float b, float c)
{
float z;
if (a != max(a, b, c) || min(a, b, c))z = a;
else if (b != max(a, b, c) || min(a, b, c))z = b;
else z = c;
return(z);
}