Fibonacci number - thought to understand recursion

Recursion

Honestly recursive bit slow, a large number of recursive calls can create a copy function, spend a lot of time and memory, mainly in the waste stack space

#include <stdio.h>

int Fbi(int i){
    if(i<2){
        return i==0?0:1;
    }
    return Fbi(i-1)+Fbi(i-2);
}

int main(void){
    int i;
    for(int i=0;i<40;i++){
        printf("%d ",Fbi(i));
    }
    return 1;
}
Published 19 original articles · won praise 1 · views 3129

Guess you like

Origin blog.csdn.net/qq_41603639/article/details/104865125