cwtests/cw04/fib.while
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 09 Oct 2021 12:29:15 +0100
changeset 843 97b622202547
parent 836 a3418ee8c404
child 852 8706b846a3e0
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
836
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
write "Fib";
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
read n;
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
minus1 := 0;
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
minus2 := 1;
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
while n > 0 do {
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
temp := minus2;
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
minus2 := minus1 + minus2;
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
minus1 := temp;
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
n := n - 1
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
};
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
write "Result";
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
write minus2