author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Mon, 26 Nov 2012 01:11:55 +0000 | |
changeset 80 | 191daa3ee29e |
parent 76 | 373cf55a3ca5 |
child 83 | bd61b03b9eaa |
permissions | -rw-r--r-- |
80
191daa3ee29e
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
76
diff
changeset
|
1 |
/* Fibonacci Program |
191daa3ee29e
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
76
diff
changeset
|
2 |
input: n |
191daa3ee29e
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
76
diff
changeset
|
3 |
output: fib_res */ |
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
73
diff
changeset
|
4 |
|
76
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
5 |
n := 90; |
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
73
diff
changeset
|
6 |
minus1 := 0; |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
73
diff
changeset
|
7 |
minus2 := 1; |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
73
diff
changeset
|
8 |
temp := 0; |
80
191daa3ee29e
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
76
diff
changeset
|
9 |
while n > 0 do { |
73
27469183da75
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
temp := minus2; |
27469183da75
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
minus2 := minus1 + minus2; |
27469183da75
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
minus1 := temp; |
27469183da75
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
n := n - 1 |
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
73
diff
changeset
|
14 |
}; |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
73
diff
changeset
|
15 |
fib_res := minus2; |
76
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
16 |
write fib_res |
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
73
diff
changeset
|
17 |