Consider the following algorithm x 1 x x x x x 2 x x 4 Wh

Consider the following algorithm.

x 1

x x + x

x x + 2

x x + 4

What is the value of x after the algorithm finishes?

x 1

for

i \"is {1, 2, 3}

do
     \"beginloop.gif\" for

j \"is {1, 2, 3, 4}

do
         

x x + x

for

k \"is {1, 2, 3, 4, 5}

do
\"beginloop.gif\"

x x + 2

\"endloop.gif\" \"endloop.gif\"

x x + 4

Solution

for i=1

j loop will run 4 times so x becomes 5

then it goes to k loop and runs for 5 values it becomes 35

for i=2

j loop will run 4 times so x becomes 39

then it goes to k loop and runs for 5 values it becomes 69

for i=3

j loop will run 4 times so x becomes 73

then it goes to k loop and runs for 5 values it becomes 103

Hence the final value of x is 103

Consider the following algorithm. x 1 x x + x x x + 2 x x + 4 What is the value of x after the algorithm finishes? x 1 for i {1, 2, 3} do for j {1, 2, 3, 4} do

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site