#include<stdio.h>
#include<math.h>
double triangleArea(int a, int b, int c);
int main()
{
printf("请输入三角形的三条边长:\n");
int a, b, c;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
double area = triangleArea(13, 14, 15);
printf("triangle area is %f.\n", area);
return 0;
}
double triangleArea(int a, int b, int c)
{
double p = (a + b + c) / 2.0;
return sqrt(p * (p - a) * (p - b) * (p - c));
}
结果如下:
请输入三角形的三条边长:
13
14
15
triangle area is 84.000000.
Press any key to continue
注意:输入的三条变长要能够组成一个三角形才可以。
网友评论