286,315 views
1 vote
1 vote
CLS
N = 1
FOR J = 1 TO 5
PRINT N
N = 10*N+1
NEXT J
END

User JuliusG
by
2.6k points

1 Answer

20 votes
20 votes

Answer:

1

11

111

1111

11111

Step-by-step explanation:

Given

The above QBasic code

Required

The output

The iteration on the third line is repeated 5 times; i.e. for values of j from 1 to 5.

In each iteration, the value of N is printed and the next value is calculated.

Initially, the value of N is 1 ---- on line 2

So, 1 is printed first. The next value of N is as follows:


N = 10 * N + 1 --- we keep replacing N (on the right-hand side) with current N value.

So, we have:


N = 10 * 1 + 1 =11


N = 10 * 11 + 1 = 111


N =10 *111+1 = 1111


N =10 *1111+1 = 11111

User Johnfo
by
2.7k points