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.
cevap : 4613732
clear all;
clc;
close all;
number_1 = 1;
number_2 = 2;
sum = number_1 + number_2;
for i=1:(10-2)
temp = sum;
sum = sum + number_2;
sum = temp + sum;
end
clear all;
clc;
close all;
first = 1;
second = 2;
sum = first + second;
new_sum = 0;
for i=1:(32-3)
first = second;
second = sum;
sum = first + second;
if(mod(sum,2) == 0)
new_sum = sum + new_sum;
end
end
% en bastaki 2'yi cift sayilarin toplamina katmadigindan sonda manual olarak toplamak lazim
new_sum = new_sum + 2;