fib.while
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 28 Nov 2012 07:00:35 +0000
changeset 82 06c3ec0b452e
parent 80 191daa3ee29e
child 83 bd61b03b9eaa
permissions -rw-r--r--
updated
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
     3
   output: fib_res */
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     4
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
     5
n := 90;
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;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     8
temp := 0;
80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
     9
while n > 0 do {
73
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
       temp := minus2;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
       minus2 := minus1 + minus2;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
       minus1 := temp;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
       n := n - 1
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    14
};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    15
fib_res := minus2;
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    16
write fib_res 
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    17