fib.while
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 23 Nov 2012 21:21:27 +0000
changeset 75 898c25a4e399
parent 73 27469183da75
child 76 373cf55a3ca5
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    10
n := 9;
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;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    21
print fib_res 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    22