Nic*_*ner 4 c math visual-studio-2010
我需要在此C代码中访问数学函数需要什么包含语句?
unsigned int fibonacci_closed(unsigned int n) {
double term_number = (double) n;
double golden_ratio = (1 + sqrt(5)) / 2;
double numerator = pow(golden_ratio, term_number);
return round(numerator/sqrt(5));
}
Run Code Online (Sandbox Code Playgroud)
我试过#include <math.h>但似乎没有这样做.
我正在使用Visual Studio 2010(Windows 7).这是错误:
1>ClCompile:
1> fibonacci_closed.c
1>c:\users\odp\documents\visual studio 2010\projects\fibonacci\fibonacci\fibonacci_closed.c(7): warning C4013: 'round' undefined; assuming extern returning int
1>fibonacci_closed.obj : error LNK2019: unresolved external symbol _round referenced in function _fibonacci_closed
Run Code Online (Sandbox Code Playgroud)
Mit*_*eat 15
Round()math.h对于Windows库不存在.限定:
static inline double round(double val)
{
return floor(val + 0.5);
}
Run Code Online (Sandbox Code Playgroud)
更新:响应您的评论,sqrt()定义于math.h