progs/fib.while
author Christian Urban <urbanc@in.tum.de>
Mon, 24 Sep 2018 11:05:39 +0100
changeset 558 447ed6c7cdad
parent 275 618c7640cf66
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 207
diff changeset
     1
write "Fib";
272
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     2
read n;  
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
     3
minus1 := 0;
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
     4
minus2 := 1;
80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
     5
while n > 0 do {
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
     6
       temp := minus2;
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
     7
       minus2 := minus1 + minus2;
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
     8
       minus1 := temp;
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
     9
       n := n - 1
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    10
};
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
    11
write "Result";
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
    12
write minus2 
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    13