作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试初始化一个数组,这样我就可以使用一个简单的 if 语句来检查一个值是否已放入数组中。
这可能吗?
这是我的代码
double number[1024] = {non-numeric value}
int i = 0;
while(1){
if (number[i] != non-numeric value){
printf ("%f", number[i]);
i++;
}
else
break;
}
最佳答案
要将数据初始化为 NaN,请使用 NAN
<math.h>
中定义的宏
#include <math.h>
// initialize to all NaNs
for (int i=0; i<1024; ++i) number[i] = NAN;
要检查 NaN,请使用 isnan
来自 <math.h>
的宏
if (!isnan(number[i])) {
// do something if the value isn’t NaN.
}
关于c - 如何将数组初始化为非数字值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15907384/
我是一名优秀的程序员,十分优秀!