Can someone please explain this
1. Determine the output
a = 3
b = 4
c = 10
While a < c
a = a + 2
b = b * 2
Endwhile
Output a, b, c
2. Determine the output
k = 4
m = 0
n = 7
While j < k
m = 5
While m < n
Ouput “X”
m = m + 1
Endwhile
j = j + 1
Endwhile
Output j, k, m, n
1) final output values of a, b, c will be:
a=11
b=64
c=10
Here the while loop starts with initial values as a=3, b=4 and c=10
Since (a<c) i.e 3<10 the loop executes as follows
a=a+2 (3+2)
b=b*2 (4*2)
after first iteration, a=5 and b=8
Since (a<c) i.e 5<10, second iteration begins:
a=a+2 (5+2)
b=b*2 (8*2)
after second iteration, a=7, b=16
since (a<c) i.e 7<10, third iteration begins:
a=a+2 (7+2)
b=b*2 (16*2)
after third iteration, a=9,b=32
Since (a<c) i.e 9<10, fourth iteration begins:
a=a+2 (9+2)
b=b*2 (32*2)
after fourth iteration, a=11, b=64
Now, since (a<c) evaluates to false I.e 11 is not less then 10, the loop stops.
Hence giving the final values as:
a=11
b=64
c=10
Get Answers For Free
Most questions answered within 1 hours.