Question

Hi,can somone explain the algorithm and prove that b = 6? Thank you. What is printed...

Hi,can somone explain the algorithm and prove that b = 6?

Thank you.

What is printed by the pseuodode algorithm shown below when x = 5?

a = 1
b = 0

repeat until a equals x
  b = b + a
  a = a + 1

print b

what is the value of b?

Homework Answers

Answer #1

Question:

a = 1
b = 0

repeat until a equals x
  b = b + a
  a = a + 1

print b

ANS:

This algorithm is adding 1 to variable a after each step until a==x, While b is being incremented by b+a so finally the value of b after the loop ends are b=10. You can look below each step

x=5

STEP 1:

b=1+0=1

a=1+1=2

STEP2:

b=1+2=3

a=2+1=3

STEP3:

b=3+3=6

a=3+1=4

STEP4:

b=6+4=10

a=4+1=5

Now as a==x which is 5 so loop will exit and it will print b=10

(Proving when b will be equal to 6:

in Step 3

b=6 When a=4)

COMMENT DOWN BELOW FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Hi, can this problem be worked out in detail please! Thank You. Answer b was wrong...
Hi, can this problem be worked out in detail please! Thank You. Answer b was wrong 1. Starting with a stock solution containing 60 mg/dL of glucose, and using dH2O as your diluting solution, you need to make 3 mL of each of the following glucose solutions: 60 mg/dL, 30 mg/dL, 15 mg/dL, 7.5 mg/dL, 3.75 mg/dL, and 1.875 mg/dL.. What is the volume of arrow E? a. V1 x 2 b. V1 x df c. V1 + V2 d....
Epigenetic Basis of Mental Illness Summarize and explain what the article is about! (CAN SOMONE PLEASE...
Epigenetic Basis of Mental Illness Summarize and explain what the article is about! (CAN SOMONE PLEASE HELP ON THIS!!!!) What are the authors views? What methods were used? Most interesting part of article? The article is provided below in the web link (copy and paste it will direct you to the article) Name of article: Epigenetic Basis of Mental Illness https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4826318/
Hi. I have two questions about the linear algebra. 1. Prove that a linear transform always...
Hi. I have two questions about the linear algebra. 1. Prove that a linear transform always maps 0 to 0. 2. Suppose that S = {x, y, z} is a linearly dependent set. Prove that every vector v in the span of the set S can be expressed as a linear combination in more than one way. Will thumb up for both answers. Thank you so much!
Problem 1. (1 point) The SolEc algorithm shown below is used with a = 0, b...
Problem 1. (1 point) The SolEc algorithm shown below is used with a = 0, b = 2 and n = 3. What is the value of c on the line Write c? Function z <- f (x) z = 85−99x + 15x2 − x3; End Function algorithm SolEc Read a, b, n; For i From 1 To n Do c = (a + b) / 2; Write a, ",", c, ",", b; If f (a) * f (c) <0...
Hi, could you please explain step-by-step what to do? Thank you. Two glass bulbs, each with...
Hi, could you please explain step-by-step what to do? Thank you. Two glass bulbs, each with the same volume, are connected together (and open to each other) and filled with Ar(g). When the two bulbs are immersed in a water bath at 85°C, the gas pressure is 0.78 atm. One of the bulbs is then removed (but not disconnected from the other) from the water bath at 85°C and immersed in a water bath at 22°C. Now, what is the...
Hi, I don’t know how to solve? What would be the explanation? Can you please solve...
Hi, I don’t know how to solve? What would be the explanation? Can you please solve for me using step by step? Thank you! ?? The correlation between two variables A and B is .25 with a p- value of .08. What can we conclude?
hi guys , using this definition for limits in higher dimensions : lim (x,y)→(a,b) f(x, y)...
hi guys , using this definition for limits in higher dimensions : lim (x,y)→(a,b) f(x, y) = L if 1. ∃r > 0 s.th. f(x, y) is defined when 0 < || (x, y) − (a, b) || < r and 2. given ε > 0 we can find δ > 0 s.th. 0 < || (x, y) − (a, b) || < δ =⇒ | f(x, y) − L | < ε how do i show that this is...
Can you explain it? Thank you! A ship is filled with 5 × 105 m3 of...
Can you explain it? Thank you! A ship is filled with 5 × 105 m3 of gasoline at a refinery in southern California when the temperature is 27.2 °C. When the ship arrives in NYC, the temperature is -3 °C. If the coefficient of volumetric expansion for gasoline is 9.50 × 10–4/C°, how much has the volume of the gasoline decreased when it is unloaded in NYC?
Hi, could you explain me what we do with salvage value when it comes to calculating...
Hi, could you explain me what we do with salvage value when it comes to calculating cash flows from assets
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...