打印功能返回(INT)和浮点数常数的乘法结果
我遇到一个问题,即函数somme_diagonale在主机中返回正确的结果,但是一旦我将其乘以(2 /9)并打印结果,结果似乎为0。
功能:功能:
{
int i, s = 0 ;
for ( i = 0 ; i < n ; i++ )
{
s = s + mat [ i ] [ i ] ;
}
return s ;
}```
call :
``` printf("resultat est : %f", ( float ) ( 2 / 9 ) * somme_diagonale ( F ) );```
i have tested that somme_diagonale ( F ) returns 165 ( int ).
can someone help me ?
i have a problem where the function somme_diagonale return the right result when called in main, but as soon as i multiply it to ( 2 / 9 ) and print the result it appears to be 0.
function :
{
int i, s = 0 ;
for ( i = 0 ; i < n ; i++ )
{
s = s + mat [ i ] [ i ] ;
}
return s ;
}```
call :
``` printf("resultat est : %f", ( float ) ( 2 / 9 ) * somme_diagonale ( F ) );```
i have tested that somme_diagonale ( F ) returns 165 ( int ).
can someone help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
hi,
为了拥有float
值,必须施放2或9个。但是,这必须在执行划分之前发生。(2/9)
产生类型int
的结果,然后然后将其施加到float
。您应该做的是用这些选项替换该代码(对不起,我不是空间的粉丝):(
Hi,
in order to have afloat
value, either the 2 or the 9 must be cast. This, though, must happen before the division is performed.(2/9)
produces a result of typeint
, which only then is cast tofloat
.What you should do is replace that piece of code with of these options (sorry in advance, I'm not a fan of spaces):