197k views
5 votes
Describe the output that will be generated by this basic program

Let x=0

FOR i = 0 to 4

FOR j = 0 to i-1

LET k = (i+j-1)

IF (k MOD 2=0) THEN

LET x= x+k

ELSE IF(k MOD 3 = 0) THEN

LET x=x+k-2

END IF

PRINT X

NEXT J

NEXT I

END

User Dharam
by
5.3k points

1 Answer

4 votes

The output that will be generated by this basic program:

This basic program deals with loops and remainder division.

First of all, an integer x is defined to be 0 and then come two loops, in nested form. First loop increments from 0 to 4 and the next loop increments from 0 to one value less than the current value of i.

After that k is defined and checked if it is divisible by 2 then it changed to x+k, and if it is divisible by 3 it is changed to x+k-2.

The output is as follows:

0

0

2

4

5

9

10

14

14

20

--------------------------------

Process exited after 0.01627 seconds with return value 0

Press any key to continue . . .

when j reaches 3, k becomes 2 which is divisible by 2 and x becomes

x+k which evaluates to 2. The process continues likewise.

User DannyMoshe
by
4.9k points