I have this fib function that doesnt do what I want it to do but that is not the problem. While debbuging the function I found that adding a loop at the end that doesnt do anything changes the whole output before it. Why is that?
void fib(int n,int v[]){
if(n<=2) v[n]=1;
else if(v[n] != 0)
cout << v[n];
else{
fib(n-1,v);
fib(n-2,v);
}
v[n] = v[n-1]+v[n-2];
cout << v[n] << endl;
}
int main(){
int v[11];
//initialize array
for (int i = 0; i < 11; ++i)
{
v[i] = 0;
}
fib(10,v);
//If I add this for loop all the outputs above change from numbers to ceros
for(int q = 0; q < 10; ++q)
{
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire