本文介绍了函数不断返回NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我知道NaN(让我说我知道首字母缩写代表Not a Number)是什么,但我不明白C ++为什么返回它-以下是数学常数e的近似值-使用调试器时函数评估良好,是在写入控制台时返回NaN
Hi guys i know what NaN(let me say i know the acronym stands for Not a Number) is but i don't understand why C++ returns it - The following is the approximation of the mathematical constant e - When using the debugger the functions evaluate fine, it's when writing to the console that it returns NaN
感谢您的反馈意见
double Factorial(int k)
{
if(k == 0)
return 1;
int value = 1;
for(int i = k; i > 0; i--)
value *= k;
return value;
}
double e(int p)
{
double value = 0.0;
for(int i = 0; i < p; i++)
{
value += 1/Factorial(i);
}
}
推荐答案
您不会在e函数中返回值.
You don't return a value in your e function.
这篇关于函数不断返回NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!