bhanu
bhanu

Reputation: 383

Runtime Error During Recursion

I am coding a program with the help of recursive calling of a function, I get correct output till my test input gets solved within 10 steps of recursion but if I increase the input value to 11 it starts giving run time error as: Segmentation fault (core dumped)

the code snippet of the function is:

void find(int x) {    
    if(ctr==n-1) {
        po[k]=x;
        k++;
        ctr--;
        return;
    } else {
        ctr++;
        find(x+a);
        ctr++;
        find(x+b);  
        ctr--;
        return;
    }
}

Upvotes: 1

Views: 189

Answers (1)

sp2danny
sp2danny

Reputation: 7687

I ran it, it needs space in po for 1024 items with x=11,
you only have 1000

Upvotes: 1

Related Questions