我定义的函数里是float为什么最后的返回值是int型

问题遇到的现象和发生背景
#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

我的解答思路和尝试过的方法
我想最后的返回值为float型

这个跟方法返回类型有关,你方法返回的类型是整型。
修改方法返回类型为float即可。
代码修改如下:

#include <stdio.h>
#include<math.h>
float 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("%f,%f,%f", &a, &b, &c);
f=area(a,b,c);
printf("area of triangle is %10.5f\n", f);
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632