function loan2()
% the program to calculate the loan interest and time to pay the loan
interest=0.0496; month_pay=1393.33; total_loan=220000; tilgung0=(month_pay*12-total_loan*interest)/total_loan; tilgung0
rest(1)=1;
for ii=1:4000 rest(ii+1)=rest(ii)-((interest+tilgung0)/12-rest(ii)*interest/12); if rest(ii+1)<=0 iii=ii+1; break; end end
s=0; for ii=1:iii s=s+rest(ii); end s=s/iii*interest; s end
fp=fopen('loan2.out','w'); for ii=1:iii fprintf(fp,'%f %fn',ii,rest(ii)); end fclose(fp);
第27行的end(红)好像不需要写,但我也不是很确定,不过出来的结果是一样的,只是少了warning. |