What include statement do I need to access the math functions in this C code?
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));
}
I tried #include <math.h>
but that didn't seem to do it.
I'm using Visual Studio 2010 (Windows 7). This is the error:
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
Round()
does not exist in math.h
for the Windows libraries. Define:
static inline double round(double val)
{
return floor(val + 0.5);
}
UPDATE: in response to your comment, sqrt() is defined in math.h
Round was added to C in C99 standards which is not supported by your compiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With