fib.while
changeset 84 719fd738d2a0
parent 83 bd61b03b9eaa
equal deleted inserted replaced
83:bd61b03b9eaa 84:719fd738d2a0
     1 /* Fibonacci Program
     1 /* Fibonacci Program
     2    input: n
     2    input: n
     3    output: fib_res */
     3 */
     4 
     4 
     5 n := 19;
     5 n := 19;
     6 minus1 := 0;
     6 minus1 := 0;
     7 minus2 := 1;
     7 minus2 := 1;
     8 temp := 0;
       
     9 while n > 0 do {
     8 while n > 0 do {
    10        temp := minus2;
     9        temp := minus2;
    11        minus2 := minus1 + minus2;
    10        minus2 := minus1 + minus2;
    12        minus1 := temp;
    11        minus1 := temp;
    13        n := n - 1
    12        n := n - 1
    14 };
    13 };
    15 fib_res := minus2;
    14 write minus2 
    16 write fib_res 
       
    17 
    15