What is the value of n and counter when the code below is executed?
n = 256; counter = 1; while n ~= 1 if rem(counter,2) == 0
n = n/2;
else
n = n/4;
end counter = counter + 1 ; end
a.
n=1;
counter = 6
b.
n=5;
counter = 6;
c.
n=6;
counter = 256;
d.
n=256
counter = 6
e.
n=128;
counter=64;
counter = 1
n = 256
while 256 != 1
1%2 =1, so
n = n/4 = 64
counter = 2
2%2 = 0
n = n/2 = 32
counter = 3
3%2 = 1
n = n/4 = 8
counter = 4
4%2 = 0
n = n/2 = 4
counter = 5
5%2 = 1
n = n/4 = 1
counter = 6
breaks the loop because condition fails for n is 1
So, n = 1
counter = 6
Answer : A
Get Answers For Free
Most questions answered within 1 hours.