can someone please help for me to change this function to iterative?

int recursive(int n)
{
    int total = 0;
    if(n>=3)
        return recursive(n-1) + 2*recursive(n-2) + 2*recursive(n-3);
    else if(n>=2)
        return  total + recursive(n-1) + 2*recursive(n-2);
    else
        return  total+1;
}

Recommended Answers

Good to hear. Please remember to mark this solved thanks.

Jump to Post

All 3 Replies

or at least a step in the right direction

Nevermind. I solved it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.