Quiz Question

I was taking a quiz and I came across the following code. I didn't know how to go about solving the code would someone please be able to elaborate on what the code is supposed to do? It was in pseudocode so please excuse the improper code. Thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Set the value of A1 to 3
Set the value of A2 to 7
Set the value of A3 to 2
Set the value of A4 to 4
Set i to 1
Set m to 99
Set n to 99

while (i <= 4) do
  If Ai < m then
 {    set m to Ai
     set n to i
     increment 1 to i
 }

set y = (m + n)
cout << y ;
I think its find the lowest number in array then add it with its index number
All you have to do is to keep track on what the values are and how they change.

At start i==1 and therefore i<=4 is true and thus the body of while loop is evaluated.
A1==3 and thus A1<m. The m changes to 3, the n changes to 1 and i changes to 2.

We are back to line 9. The loop condition (2<=4) still evaluates true, and so forth ...
I still so we are only dealing with A1 or are we dealing with A1-A4? The part that confuses me the most is line 10 I don't know what Ai means. If it just means use the lowest number why wasn't A3 used instead? Thanks for the responses.
closed account (48T7M4Gy)
Ai means if i is 3 for example then Ai is A3
Topic archived. No new replies allowed.