Skip to content

Instantly share code, notes, and snippets.

@chiragmongia
Created July 31, 2013 06:28
Show Gist options
  • Select an option

  • Save chiragmongia/6119797 to your computer and use it in GitHub Desktop.

Select an option

Save chiragmongia/6119797 to your computer and use it in GitHub Desktop.
#Question- Fibonacci - Yield
#Fibonacci Series upto 1000 using 'yield'.
def fibonacci_series(number)
@first_number = 0
@second_number = 1
while @first_number <= number
yield(@first_number, @second_number)
end
end
#Main
print "Enter the number for FIBONACCI SERIES: "
number = gets.to_i
fibonacci_series(number) do
p @first_number
@first_number, @second_number = @second_number, @second_number + @first_number
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment