0
Please what is the error with this my code... Fibonacci series
Fibonaccis series showing runtime error. https://code.sololearn.com/c5hn1wnX3otP/?ref=app
5 Respuestas
+ 3
So I modified it tho I don't give solutions but I kinda wanted to see if I can implement it correctly
int main() {
int num;
int i;
for(i=3;i>=-1;i--){
num=fibonacci_n(i);
printf("%d\n",num);
}
}
int fibonacci_n(int n)
{
int m=1;
int count;
for(count=0;count<=n;count++)
{
m+=count;
}
return m;
}
+ 3
for(count=1;count<=n;count++)
{
n+=count;
}
this is running for infinite number of times.
because count would never be greater than n (which means count<=n is always true) since with every iteration you are adding n+=count(n=n+count)
so a solution would be to use a new variable for n
+ 2
I dunno C so I am not able to solve it but you need to read your program to see what you are doing ,your program is running endlessly with no way to stop that function with n-1 and also you are adding count to n while keeping count<n ,really?
0
Thanks alot.
0
I have edited the code. If only i could mark everyones suggestion🙌🙌🙌🙌🙌