+ 3

Codes

Please guys help like all my codes and this one too https://code.sololearn.com/c5E5zA12fe9n/?ref=app

2nd Aug 2017, 12:51 PM
LordGhostX
LordGhostX - avatar
3 Réponses
+ 3
https://code.sololearn.com/c8u1CiN16ln6/?ref=app
2nd Aug 2017, 1:26 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
because two values you have already printed.. and the fibnoacci series needs first two values to be displayed.
2nd Aug 2017, 2:56 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
Thanks a lot sir, I didn't know that, I've made the correction in my own way and one more thing if an input of 5 is given to your code it displays 7 members of the series instead of 5, all you have to do is subtract 2 from the n variable before passing it to the .times correct it as so #Program to print out n numbers of the Fibonacci series n = gets.to_i case n when 0 puts "Enter a valid input" when 1 puts "0\n" when 2 puts "0\n1\n" else a,b,c = 0,1,0 puts a,b (n-2).times do c = a + b a = b b = c puts "#{c}\n" end end if n != 0 puts "\nThe first #{n} member(s) of the Fibonacci series" end
2nd Aug 2017, 2:54 PM
LordGhostX
LordGhostX - avatar