I have writen a code to calculate for every d numbers all the fibonacci numbers that are even, but it doesn't seem to work for large d such as 100 or 150. Can you tell me what i did wrong? My code is this
function y = evenFibo(d)
%y = x;
fibonacci(1) = 0; fibonacci(2) = 1;
for i = 3 : d +1
fibonacci(i) = fibonacci(i-1) + fibonacci(i-2) ;
end
fibonacci = nonzeros(fibonacci);
even = [];
for i = 1 : d
if rem (fibonacci(i),2) == 0 == 1 %einai artios
even = [even, fibonacci(i)];
fibonacci(i)
end
end
y= numel(even);
end
Best Answer