# Math Help - Algorithm

1. ## Algorithm

pu

2. Originally Posted by chillerbros17
Consider the following algorithm.

Input X
A:= 0
B:= 0
Count:= 1
While X <>0
If > A then
Do
A:= X
B:= Count
End Do
Input X
Count :=Count + 1
End While
Output A, B

Suppose the inputted values of x are:
3, 4, 2, 9, 3, 9, 2, 0, 4, 7, 1 (all values may not be used)

(a) Trace through the algorithm.

(b) Given a list of numbers, what will A output and what will B output?
1). Indentation is very helpful in following pseudo code, you can use [code]..[/code]
tags to delimit a code block where the indentation will sort of work:

Code:
Input X
A:= 0
B:= 0
Count:= 1
While X <>0
If > A then
Do
A:= X
B:= Count
End Do
Input X
Count :=Count + 1
End While
Output A, B
2). What do you want the "> A" in "If > A then" to mean?

RonL

3. X > A

4. Originally Posted by chillerbros17
Consider the following algorithm.

Input X
A:= 0
B:= 0
Count:= 1
While X <>0
If > A then
Do
A:= X
B:= Count
End Do
Input X
Count :=Count + 1
End While
Output A, B

Suppose the inputted values of x are:
3, 4, 2, 9, 3, 9, 2, 0, 4, 7, 1 (all values may not be used)

(a) Trace through the algorithm.

(b) Given a list of numbers, what will A output and what will B output?
Hi, to (a): Use a trace table. I've used the given list of numbers.
Code:
     x     A     B     count
-     0     0       1              start
3     3     1       2
4     4     2       3
2     4     2       3
9     9     3       4
3     9     3       4
9     9     4       5
2     9     4       5
0   → break off of program
output: A = 9
B = 4
EB