• Nov 15th 2008, 04:28 AM
dblbac
we were given this problem by our teacher but i am clueless on what to do. any help would be greatly appreciated.

explain what is happening in the pseudo code LOOP in one word. What is the temp referring, and what is the final output for this program:

input (12,25,11,28,14)

BEGIN
temp := a1
for I = 2 to n
if temp < ai then temp := ai
END
Print temp
• Nov 15th 2008, 06:01 AM
Rapha
Hi

Quote:

Originally Posted by dblbac
we were given this problem by our teacher but i am clueless on what to do. any help would be greatly appreciated.

explain what is happening in the pseudo code LOOP in one word. What is the temp referring, and what is the final output for this program:

input (12,25,11,28,14)

BEGIN
temp := a1
for I = 2 to n
if temp < ai then temp := ai
END
Print temp

The input are some numbers, 12, 25,11,28,14
they are unsorted.

BEGIN

temp:=a1

temp = 12 (the first element of your list)

for I = 2 to n

if temp <a_i (temp < a_2, that means i.e. if 12 < 25, then)
then temp := ai

temp = 25

well, i know this is not a good explanation, but this program searches a list (input) and the output is the biggest number (here 28)
• Nov 15th 2008, 12:34 PM
dblbac
THANKS
thanks for the help