Sie sind auf Seite 1von 4

Prof.

Hawk

Solution 6-1

Programming Logic and Design, 6th Edition


Chapter 6
Exercises
1. a. Design the logic for a program that allows a user to enter 10 numbers, then displays
them in the reverse order of their entry.
Answer:
A sample solution follows
Flowchart:

Pseudocode:
start
Declarations
num index
num SIZE = 10
num numbers[SIZE] = 0,0,0,0,0,0,0,0,0,0
getReady()

Prof. Hawk

Solution 6-2

while index < SIZE


getNumbers()
endwhile
finishUp()
stop
getReady()
index = 0
return
getNumbers()
output Enter a number for position , index
input numbers[index]
index = index + 1
return
finishUp()
output The numbers in reverse order are:
while index > 0
index = index 1
output numbers[index]
endwhile
return

b. Modify the reverse-display program so that the user can enter up to 10 numbers
until a sentinel value is entered.
Answer:
A sample solution follows
Flowchart:

Prof. Hawk

Pseudocode:
start
Declarations
num index
num SIZE = 10
num numbers[SIZE] = 0,0,0,0,0,0,0,0,0,0
string CONTINUE = Y
string moreNumbers = CONTINUE
getReady()
while index < SIZE AND moreNumbers equal to CONTINUE
getNumbers()
endwhile
finishUp()
stop
getReady()
index = 0
output Do you want to enter a number? (Y/N)
input moreNumbers
return
getNumbers()
output Enter a number for position , index
input numbers[index]
index = index + 1

Solution 6-3

Prof. Hawk

output Do you want to enter more numbers? (Y/N)


input moreNumbers
return
finishUp()
output The numbers in reverse order are:
while index > 0
index = index 1
output numbers[index]
endwhile
return

Solution 6-4

Das könnte Ihnen auch gefallen