#include<stdio.h>
#include<math.h>
int main(void)
{
float a, b, c;
double d;
double f;
printf("input a, b, c:");
scanf("%f,%f,%f" , &a, &b, &c);
if(a+b > c || a+c > b || b+c > a )
{
f = (a+b+c)/2;
d = sqrt(f*(f-a)(f-b)(f-c));
printf("%.2f", d);
}
else
printf("wrong ");
return 0;
}
解析在注释中
#include<stdio.h>
#include<math.h>
int main(void)
{
float a, b, c;
double d;
double f;
printf("input a, b, c:");
scanf("%f,%f,%f" , &a, &b, &c);
if(a+b > c && a+c > b && b+c > a ) //判断是否为三角形需要取交集
{
f = (a+b+c)/2;
d = sqrt(f*(f-a)*(f-b)*(f-c)); //乘号不能省略
printf("%.2lf", d); //double 格式化输出是lf
}
else
printf("wrong ");
return 0;
}