fib.while
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 24 Nov 2012 07:08:51 +0000
changeset 76 373cf55a3ca5
parent 75 898c25a4e399
child 80 191daa3ee29e
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     1
/*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     2
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     3
  Fibonacci Program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     4
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     5
  input: n
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     6
  output: fib_res
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     7
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     8
*/
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
     9
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    10
n := 90;
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    11
minus1 := 0;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    12
minus2 := 1;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    13
temp := 0;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    14
while n > 0 do  {
73
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
       temp := minus2;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
       minus2 := minus1 + minus2;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
       minus1 := temp;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
       n := n - 1
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    19
};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    20
fib_res := minus2;
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    21
write fib_res 
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    22