Answers for "tribonacci series c++"

C++
2

tribonacci series c++

int n;
    cin>>n;
    int a=0,b=0,c=1;
    if (n < 3) return 0;
    cout<<a<<" "<<b<<" "<<c<<" ";
    for(int i = 1; i<= n-3; i++){
        int d = a + b + c;
        cout<<d<<" ";
        a = b;
        b = c;
        c = d;
    }
Posted by: Guest on December-29-2020
0

iterative tribonacci python

def trib_iter(m):
    lista=[m]
    c=0
    d=True
    while d==True:
        novalista=[]
        for n in lista:
            if n in [0,1,2]:
                c+=1
            else:
                for i in range(1,4):
                    if n-i in [0,1,2]:
                        c+=1
                    else:
                        if n-i<0:
                            pass
                        else:
                            novalista.append(n-i)
        if novalista==[]:
            d=False
        else:
            lista=novalista
    return c
Posted by: Guest on June-21-2020

Browse Popular Code Answers by Language