close all
clear all
clc

R0 = 0.457;
E7 = 0;
V1 = R0*10^E7;
V2 = floor(V1);
while abs(V2-V1) >= 0.01
    E7=E7+1;
    V1 = R0*10^E7;
    V2 = floor(V1);
end
X(1)=floor(10^E7+0.5);
X(2)=R0*X(1);
Q(1)=floor(X(1)/X(2));
X(3)=X(1)-Q(1)*X(2);
N(1)=1;
D(1)=Q(1);
j=1;
fprintf('     j      N      D   N/D            erro (%%)\n')
fprintf('%6d %6d %6d   %10.8f  %9.4f\n',j,N(j),D(j),N(j)/D(j),(R0-N(j)/D(j))/R0*100);
Q(2)=floor(X(2)/X(3));
X(4)=X(2)-Q(2)*X(3);
N(2)=Q(2);
D(2)=Q(1)*Q(2)+1;
j=2;
fprintf('%6d %6d %6d   %10.8f  %9.4f\n',j,N(j),D(j),N(j)/D(j),(R0-N(j)/D(j))/R0*100);
while X(j+2) ~= 0
j=j+1;
Q(j)=floor(X(j)/X(j+1));
X(j+2)=X(j)-Q(j)*X(j+1);
N(j)=Q(j)*N(j-1)+N(j-2);
D(j)=Q(j)*D(j-1)+D(j-2);
fprintf('%6d %6d %6d   %10.8f  %9.4f\n',j,N(j),D(j),N(j)/D(j),(R0-N(j)/D(j))/R0*100);
end

