From my understanding T(2) is getting updated after running the program but you have assumed T(2) to be 2 at the staring of the program.This might be because in this line
for i=1:k
T(k+2-i)=(-A-(k+2-i)*(k+1-i)*T(k+2-i))/((k-i+1)*(k-i+2));
end
you are changing T(2) for i=2 and k=2.
Hence T(2) is getting updated from 0 to some other value.