浮动值可以四舍五入吗? [英] float values can b rounded off?
问题描述
嗨;
代码:
int main(无效)
{
float i = 6.10203;
printf("%d",i);
返回0;
}
给出o / p零。为什么??????
hi;
the code:
int main(void)
{
float i=6.10203;
printf("%d",i);
return 0;
}
is giving the o/p zero. why??????
推荐答案
" sushant" <第******** @ rediffmail.com>写道:
"sushant" <th********@rediffmail.com> wrote:
int main(void)
{/ i> float i = 6.10203;
printf("%d",i);
返回0;
}
给o / p零。为什么??????
int main(void)
{
float i=6.10203;
printf("%d",i);
return 0;
}
is giving the o/p zero. why??????
因为你骗了编译器。为什么要神奇地弄清楚
你想要的这种未定义的行为的几种可能解释中的哪一种?
Richard
Because you''re lying to the compiler. Why should it magically figure out
which of the several possible interpretations of this undefined
behaviour you want?
Richard
sushant写道:
sushant wrote:
hi;
代码:
int main(void)
{/ i>浮动i = 6.10203;
printf("%d",i);
返回0;
}
正在给o / p零。为什么??????
hi;
the code:
int main(void)
{
float i=6.10203;
printf("%d",i);
return 0;
}
is giving the o/p zero. why??????
1.没有适当的缩进(停止使用Google发布;
获得真正的NG客户端)。
2.我不得忘记包括STDIO.H - 荷马(好吧,不是真的)。
3.听说过强迫吗?
问候,
Jonathan。
-
我正在学习编程因为那时我可以编写
程序来更快地完成我的作业。 ; - Andy Anfilofieff
1. No proper indentation (stop using Google to post;
get a real NG client).
2. "I MUST NOT FORGET TO INCLUDE STDIO.H" - Homer (well, not really).
3. Ever heard of coercion?
Regards,
Jonathan.
--
"I''m learning to program because then I can write
programs to do my homework faster." - Andy Anfilofieff
sushant写道:
sushant wrote:
嗨;
代码:
int main(void)
{/ i> float i = 6.10203;
printf("%d",i);
你在printf()中使用了错误的转换说明符。 "%d"期望
一个int参数。使用%f相反。
返回0;
}
给o / p零。为什么??????
hi;
the code:
int main(void)
{
float i=6.10203;
printf("%d",i);
You''re using the wrong conversion specifier in printf(). "%d" expects
an int argument. Use "%f" instead.
return 0;
}
is giving the o/p zero. why??????
使用错误的转换说明符会导致不可预测的结果。
Using the wrong conversion specifier leads to unpredictable results.
这篇关于浮动值可以四舍五入吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!