【发布时间】:2014-03-23 11:28:51
【问题描述】:
有源代码。函数func的内容未知:
#include <stdio.h>
#include <math.h>
float func (void)
{
// Black box
}
int main (void)
{
float f1, f2;
int r1, r2;
f1 = 5.0f;
f2 = func();
r1 = (f1 > f2);
r2 = (f1 <= f2);
printf ("r1=%d r2=%d\n", r1, r2);
return 0;
}
需要写函数func的内容,打印出消息:
r1=0 r2=0
答案:
返回 pow(-5.0, 0.5);
或
返回 0.0/0.0;
不明白,为什么会这样?
【问题讨论】:
-
这是某种脑筋急转弯吗?
-
你知道C语言中
0.0/0.0是什么意思吗? -
@TunZarniKyaw: Both 如果
f2是NaN,f1 > f2和f1 <= f2可能为假。 -
只需输入
return NAN;。NAN是在math.h标头中定义的宏。 -
@dima 读到这个 - gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html
标签: c