//使用recursion来计算生成fibonacci series前49个数,并计算程序运行时间 #include <stdio.h> #include <time.h> double fibon(int n) { if (n == 1 || n == 2) return 1; else if (n > 2) return fibon(n-1) + fibon(n-2); else return 0; } int main() { double t = time(NULL); //纪录开始时间 for (int i = 1; i < 50; i++) { printf("%f ", fibon(i)); } double elapsed = time(NULL) - t; //计算运行时间 printf("It took %f seconds to finish. ", elapsed); return 0; }