输入三角形的三个边,求其面积
程序代码:
/*
2017年6月30日15:27:22
功能:输入三角形的三个边,求其面积。
*/
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
int main(void)
{
float a, b, c, p, s;
printf("请输入三角形的三个边长,以空格分隔:");
scanf("%f %f %f", &a, &b, &c);
if (a+b>c && b+c>a && a+c>b ) //三角形两边之和没有大于第三边,无法构成三角形
{
p = (a + b + c)/2;
s = sqrt (p*(p-a)*(p-b)*(p-c)); //sqrt函数是指的开方运算函数
printf("该三角形的面积为:%f\n", s);
}
else
printf("Error\n");
system("pause");
return 0;
}
/*
----------------
请输入三角形的三个边长,以空格分隔:5 7 8
该三角形的面积为:17.320508
----------------
*/