What will be the output if limit = 6?
Read limit
n1 = 0, n2= 1, n3=1, count = 1;
while count <= limit
count=count+1
print n3
n3 = n1 + n2
n1 = n2
n2 = n3
End While
Answers
Output is
1
1
2
3
5
8
Thats a fibo
Answer:
The final output will be : 1 1 2 3 4 5.
Explanation:
while (count <= limit)
Here, limit is 6.
count=count+1;
The count will increase and simultaneously.
for count = 1
first " 1 " will be printed.
Then
n3= n1 + n2
n3 = 0 + 1 ⇒ n3 = 1
n1 = n2 ⇒ n1 = 1
n2 = n3 ⇒ n2 = 1
for count =2
first " 1 " will be printed.
Then
n3 = n1 + n2 ⇒ n3 =2
n1 = n2 ⇒ n1 = 1
n2 = n3 ⇒ n2 = 2
for count =3
first " 2 " will be printed.
Then
n3 = n1 + n2 ⇒ n3 =3
n1 = n2 ⇒ n1 = 2
n2 = n3 ⇒ n2 = 3
Similarly, following the pattern for count = limit = 6
first " 5 " will be printed.
Then
n3 = n1 + n2 ⇒ n3 =6
n1 = n2 ⇒ n1 = 5
n2 = n3 ⇒ n2 = 6
Hence, the final printing output will be
1 1 2 3 4 5.
#SPJ3
25 MAY 2022.