Guest User

Untitled

a guest
Jul 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #
  2. #Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
  3. #
  4. #1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
  5. #
  6. #By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
  7. #
  8. #
  9.  
  10. a = 0
  11. b = 1
  12. total = total
  13. 20.times do
  14. printf("%d\n", a)
  15. sum = a+b
  16. a = b
  17. b = sum
  18. if a%2
  19. else
  20. total += a
  21. end
  22. end
  23. puts "\nThis is the total: "
  24. puts total
Add Comment
Please, Sign In to add comment