PROBLEM: 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:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
SOLUTION: Giải pháp của mình dùng khá nhiều biến. 3 biến pre_1, pre_2 và term để lần lượt lưu 3 giá trị đó là số fibonacci và 2 số phía trước nó. Mỗi vòng lặp là 3 biến này được cập nhật giá trị mới.
FULL CODE:
Mong nhận được sự góp ý từ bạn đọc !
Edited by me.






Không có nhận xét nào:
Đăng nhận xét