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

时间:2022-05-30
本文章向大家介绍京东C/C++工程师笔试题,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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

#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