题解 | #Fibonacci#

Fibonacci

https://www.nowcoder.com/practice/17ad6908e36a49f4b06ea96936e8bb25

#include <iostream>
using namespace std;
int fib(int n){
    if(n==1){
        return 1;
    }
    if(n==0) return 0;
    return fib(n-1)+fib(n-2);
}
int main() {
    int n;
    while (cin >> n) { // 注意 while 处理多个 case
        cout << fib(n)<< endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

06-18 13:28
已编辑
门头沟学院 Web前端
爱睡觉的冰箱哥:《给予你300的工资》,阴的没边了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务