cwtests/cw03/fib.while
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 05 Sep 2021 23:51:37 +0100
changeset 836 a3418ee8c404
child 853 568671822d52
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 
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13