1. Write a program that does something interesting with an array of 10 numbers.
ID: 3538412 • Letter: 1
Question
1. Write a program that does something interesting with an array of 10 numbers.
2. Be sure to write a reasonable specification and test scenario.
Example
Requirements Specification: The program should do the following:
Psuedo-code:
// Simple approach
MAIN
Declare MAX = 10 as integer
Declare i, arr[MAX] as integers
for (i = 0; i < MAX; i++)
Set arr [i] = i * 5
end for
for (i = 0; i < MAX; i++)
write i + " - " + arr[i]
end for
END
Scenarios:
input: <none>
output:
0 - 0
1 - 5
2 - 10
3 - 15
4 - 20
5 - 25
6 - 30
7 - 35
8 - 40
Explanation / Answer
// pseudocode to print an array in reverse order
MAIN Declare max_elem =10
integer Declare integer array[max_elem] ,i i<--0
//input loop
while i=0
do
{ write "array[ "
write i write "] = "
write array[i]
write nextline
i<--i-1 }
input: none
output:
array[0]= 0
array[1]=1
array[2]=2
array[3]=3
array[4]=4
array[5]=5
array[6]=6
array[7]=7
array[8]=8
array[9]=9
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.