fib.while
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 05 Dec 2012 04:13:12 +0000
changeset 86 6a7fe83820c8
parent 84 719fd738d2a0
permissions -rw-r--r--
added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
     1
/* Fibonacci Program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
     2
   input: n
84
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 83
diff changeset
     3
*/
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     4
83
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
     5
n := 19;
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     6
minus1 := 0;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     7
minus2 := 1;
80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
     8
while n > 0 do {
73
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
       temp := minus2;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
       minus2 := minus1 + minus2;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
       minus1 := temp;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
       n := n - 1
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    13
};
84
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 83
diff changeset
    14
write minus2 
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    15