How to resolve the algorithm Continued fraction step by step in the ZX Spectrum Basic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Continued fraction step by step in the ZX Spectrum Basic programming language
Table of Contents
Problem Statement
The task is to write a program which generates such a number and prints a real representation of it. The code should be tested by calculating and printing the square root of 2, Napier's Constant, and Pi, using the following coefficients: For the square root of 2, use
a
0
= 1
{\displaystyle a_{0}=1}
then
a
N
= 2
{\displaystyle a_{N}=2}
.
b
N
{\displaystyle b_{N}}
is always
1
{\displaystyle 1}
. For Napier's Constant, use
a
0
= 2
{\displaystyle a_{0}=2}
, then
a
N
= N
{\displaystyle a_{N}=N}
.
b
1
= 1
{\displaystyle b_{1}=1}
then
b
N
= N − 1
{\displaystyle b_{N}=N-1}
. For Pi, use
a
0
= 3
{\displaystyle a_{0}=3}
then
a
N
= 6
{\displaystyle a_{N}=6}
.
b
N
= ( 2 N − 1
)
2
{\displaystyle b_{N}=(2N-1)^{2}}
.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Continued fraction step by step in the ZX Spectrum Basic programming language
Source code in the zx programming language
10 LET a0=1: LET b1=1: LET a$="2": LET b$="1": PRINT "SQR(2) = ";: GO SUB 1000
20 LET a0=2: LET b1=1: LET a$="N": LET b$="N": PRINT "e = ";: GO SUB 1000
30 LET a0=3: LET b1=1: LET a$="6": LET b$="(2*N+1)^2": PRINT "PI = ";: GO SUB 1000
100 STOP
1000 LET n=0: LET e$="": LET p$=""
1010 LET n=n+1
1020 LET e$=e$+STR$ VAL a$+"+"+STR$ VAL b$+"/("
1030 IF LEN e$<(4000-n) THEN GO TO 1010
1035 FOR i=1 TO n: LET p$=p$+")": NEXT i
1040 PRINT a0+b1/VAL (e$+"1"+p$)
1050 RETURN
You may also check:How to resolve the algorithm Jaro-Winkler distance step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Quaternion type step by step in the Tcl programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the Lasso programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the Action! programming language
You may also check:How to resolve the algorithm Problem of Apollonius step by step in the Wren programming language