Please what is the error with this my code... Fibonacci series | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Please what is the error with this my code... Fibonacci series

Fibonaccis series showing runtime error. https://code.sololearn.com/c5hn1wnX3otP/?ref=app

30th Apr 2020, 8:17 PM
Umunnakwe Ephraim Ekene
Umunnakwe Ephraim Ekene - avatar
5 Respostas
+ 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; }
30th Apr 2020, 9:33 PM
Abhay
Abhay - avatar
+ 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
30th Apr 2020, 8:51 PM
Rohit
+ 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?
30th Apr 2020, 8:40 PM
Abhay
Abhay - avatar
0
Thanks alot.
1st May 2020, 6:28 PM
Umunnakwe Ephraim Ekene
Umunnakwe Ephraim Ekene - avatar
0
I have edited the code. If only i could mark everyones suggestionšŸ™ŒšŸ™ŒšŸ™ŒšŸ™ŒšŸ™Œ
1st May 2020, 6:29 PM
Umunnakwe Ephraim Ekene
Umunnakwe Ephraim Ekene - avatar