# Math Help - Algorithm

1. ## Algorithm

This is in my math class, but I'm horrible at programming so don't quite get it. But, for a, b and c below, I have to find "b" (all values- note that b is an integer) that'll make the algorithm print "Hello".

NOTE: the ....... below is in place of the indentation.. wouldn't let me indent it so I used .'s to make the space.

a.)

k := b
While k < 5
........k := 2k - 1
End While
Print "Hello"

b.) Note for this one =! means not equal

k := b
While k =! 5
........k := 2k - 1
End While
Print "Hello"

c.)

k := b
While k < 5
........k := 2k + 1
End While
Print "Hello"

My teacher said another way to ask the question of finding b that'd make it print "Hello" is to find all values of b which will NOT result in an infinite loop.

2. $\text{a) You have: }$
$k:= b$

$\text{while }k < 5$

$\text{ }k := 2k - 1$

$\text{End While}$

$\text{Print "Hello"}$

The values that would print Hello would be the values that make it through the loop, so 2 < b < 5 so that the loop is executed and ended and all b > 5 so that the loop is overlooked.

$\text{b) You have: }$
$k:= b$

$\text{while }k =! 5$

$\text{ }k := 2k - 1$

$\text{End While}$

$\text{Print "Hello"}$

Obviously, b = 5 would print hello, also, b = 3 would print hello.

$5 := 2k - 1$

$6 := 2k$

$3 := k := b$

So, the answers are 5 and 3.

$\text{c) You have: }$
$k:= b$

$\text{while }k < 5$

$\text{ }k := 2k + 1$

$\text{End While}$

$\text{Print "Hello"}$

$\text{The program will print Hello }\forall \ b \in \mathbb{N}\text{ including 0.}$