问题遇到的现象和发生背景
#include <stdio.h>
#include<math.h>
int area (float a, float b,float c)
{
float d, s;
d = (a + b + c) / 2;
s = sqrt(d * (d - a) * (d - b) * (d - c));
return s;
}
int main()
{
float a, b, c,f;
printf("please input 3 sides of one triangle:\n");
scanf_s("%f,%f,%f", &a, &b, &c);
f=area(a,b,c);
printf("area of triangle is %10.5f\n", f);
}
算术溢出: 使用 4 字节值上的运算符 * ,然后将结果转换到 8 字节值。在调用运算符 * 之前将值强制转换为宽类型可避免溢出(io.2)。
”=“ 从“double”转换到“float”,可能丢失数据 8
“=”: 从“int”转换到“float”,可能丢失数据 18