标签:recursion print second col nis bsp 个数 printf ret
//使用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\n", fibon(i)); } double elapsed = time(NULL) - t; //计算运行时间 printf("It took %f seconds to finish.\n", elapsed); return 0; }
[C]fibonacci series, recursion, time.h
标签:recursion print second col nis bsp 个数 printf ret
原文地址:https://www.cnblogs.com/profesor/p/13227760.html