author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Fri, 29 Nov 2013 09:01:08 +0000 | |
changeset 211 | deece8c6cf3a |
parent 208 | bd5a8a6b3871 |
child 215 | 828303e8e4af |
permissions | -rw-r--r-- |
207
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
1 |
/* Fibonacci Program |
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
2 |
input: n |
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
3 |
*/ |
208
bd5a8a6b3871
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
207
diff
changeset
|
4 |
write "Fib"; |
211
deece8c6cf3a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
208
diff
changeset
|
5 |
read n; |
deece8c6cf3a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
208
diff
changeset
|
6 |
//n := 19; |
207
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
7 |
minus1 := 0; |
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
8 |
minus2 := 1; |
80
191daa3ee29e
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
76
diff
changeset
|
9 |
while n > 0 do { |
207
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
10 |
temp := minus2; |
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
11 |
minus2 := minus1 + minus2; |
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
12 |
minus1 := temp; |
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
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 |
}; |
207
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
15 |
write "Result"; |
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
182
diff
changeset
|
16 |
write minus2 |
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
73
diff
changeset
|
17 |