changeset 147 | 4725bba8ef26 |
parent 93 | 4794759139ea |
child 178 | d36363d648e3 |
--- a/progs/fib.while Mon Oct 21 15:02:54 2013 +0100 +++ b/progs/fib.while Tue Oct 22 23:17:53 2013 +0100 @@ -1,15 +1,13 @@ -/* Fibonacci Program - input: n -*/ - -n := 19; -minus1 := 0; -minus2 := 1; +write "Input a number "; +read n; +x := 0; +y := 1; while n > 0 do { - temp := minus2; - minus2 := minus1 + minus2; - minus1 := temp; - n := n - 1 + temp := y; + y := x + y; + x := temp; + n := n - 1 }; -write minus2 +write "Result "; +write y