Ask your own question, for FREE!
Mathematics 8 Online
OpenStudy (anonymous):

Consider the following algorithm. x ← 1 for i is in {1, 2, 3, 4} do for j is in {1, 2, 3} do x ← x + x for k is in {1, 2, 3, 4, 5, 6} do x ← x + 1 x ← x + 5 Count the number of + operations done by this algorithm.

OpenStudy (chillout):

Each outside loop will run the insider loop for every iteration. the "k" loop is inside the "j" loop, which in turn is inside the "i" loop. As it turns out, for every iteration of "j", we will have 1 + (6*2) = 13 operations. As we have 3 "j" iterations, this gives 39 "+" operations for each "i" iteration. So, for 4 "i" iterations, we have 4*39 = 156 "+" operations.

OpenStudy (anonymous):

got it!! the answer is 60

OpenStudy (chillout):

How's it? Please give your solution.

OpenStudy (anonymous):

value of i = 4 for j = 3 for k = 6 x 2 4(3 + (6x2)) =60

OpenStudy (anonymous):

i don't know if it makes sense. but I got it right!

OpenStudy (chillout):

Nope. I just tested it. Check it at http://ideone.com/GsQ3pj You should be able to understand. The program output is Success time: 0 memory: 3096 signal:0 156

OpenStudy (chillout):

Do you understand any programming languages?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!