京东C/C++工程师笔试题

这个是今天在伯乐在线看到的,以为挺有趣的,就拿来看看。题目以下:
下列程序执行后,输出的结果为( )code

#include <stdio.h>
int cnt=0;
int fib(int n){
  cnt++;
  if(n==0) 
    return 1; 
  else if(n==1) 
    return 2; 
  else 
    return fib(n-1)+fib(n-2);
}
void main()
{
  fib(8);
  printf("%d",cnt);
}
  • 41
  • 67
  • 109
  • 177
    我在Mac上用gcc编译经过后的结果为:
n=1:1
n=2:4
n=3:9
n=4:18
n=5:33
n=6:58
n=7:99
n=8:166
相关文章
相关标签/搜索