+ 1

Why my program for fibonicci series is giving error?

https://code.sololearn.com/c74H9XpNjHRv/?ref=app

28th May 2017, 12:14 PM
Amandeep
Amandeep - avatar
4 Respuestas
+ 4
It was because the compiler could not decide whether it will be initialized. If there is a possibility that initialization will not be performed by a branch such as if statement, a compile error occurs.
28th May 2017, 12:33 PM
Suyasa
Suyasa - avatar
+ 4
Because you haven't initialised (a) and( b) . Do this int a=0,b=0,c; Dont know about Fibonacci series but whats happening here is that the input goes to last else where it says c=a+b since you never put any value to a and b , so it shows error . It should be initialised differently for Fibonacci but thats what is causing the error .
28th May 2017, 12:21 PM
Utkαrsh
Utkαrsh - avatar
+ 2
But in for loop, if(i==0) needs to be executed first, that initialise the value of a.
28th May 2017, 12:23 PM
Amandeep
Amandeep - avatar
+ 1
It means i have to initialise a and b at the time of declaration i.e int a=0,b=1. Hm, i got it. Thanks all.
28th May 2017, 12:36 PM
Amandeep
Amandeep - avatar