带有数值的伪代码流程图

时间:2018-10-26 10:36:29

标签: algorithm

If ‘n’ is 6, what will be the final value of b?

我正在努力理解这个算法。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您需要写下这些值并逐步执行流程图。

Initial:  n=6, a=0; b=1

is a < n?  Yes.
Display a (0)
a = b (1)
b = a+b = 1+1 = 2;

state n=6, a=1, b=2

is a < n?  Yes.
Display a (1)
a = b (2)
b = a+b = 2+2 = 4;

state n=6, a=2, b=4

is a < n? ...

continue until a is not < n