我试图让用C一个简单的计算器斐波纳契但是当编译gcc
告诉我,我错过了战俘和地板的功能。怎么了?未定义参考`战俘“和'地板”
代码:
#include <stdio.h>
#include <math.h>
int fibo(int n);
int main() {
printf("Fib(4) = %d", fibo(4));
return 0;
}
int fibo(int n) {
double phi = 1.61803399;
return (int)(floor((float)(pow(phi, n)/sqrt(5)) + .5f));
}
输出:
[email protected]:~/work/c/fibo$ gcc fib.c -o fibo
/tmp/ccNSjm4q.o: In function `fibo':
fib.c:(.text+0x4a): undefined reference to `pow'
fib.c:(.text+0x68): undefined reference to `floor'
collect2: ld returned 1 exit status
由于浮点精度不是无限的,这会给错误的答案为'N' – vonbrand 2013-01-20 05:14:04