It could be n is lower than 8.
Lines 5-12 will fail if n is less than 7.
If n is less than 7, this line will cause segmentation fault :
t[7] = 1;
When n is 6, the vector has 7 elements. The element t[7]
does not exist.
int nbSeqRugbyDyn(int n) {
std::vector<int> t;
for (int i=0; i<=n; i++) t.push_back(i);
if(n==0)
return 1;
else
if(n==1)
return 0;
else
if(n==2)
return 0;
else
if(n==3)
return 2;
else
if(n==4)
return 0;
else
if(n==5)
return 1;
else
if(n==6)
return 4;
else
if(n==7)
return 1;
else
for(int i=8;i<n;i++){
t[i]=t[i-7]+t[i-5]+2*t[i-3];
}
return t[n];
}
still have the same problem
What is the 'n'?
I have a problem if I pass char in 'n'
Are you sure the segmentation fault is happening inside this function? Even if it is, it might not be what is causing it.