CS117 Programming Methodology
Fall 1999
Analyze the program on the last page and simulate the execution of the program using the pencil-and-paper method demonstrated in class. Make sure that the following are made clear in your simulation table:
Hand in your completed simulation table to me (RTH) by Monday, November 15th. in class.
integer function maxmin(a, t)
integer a(3)
integer t
integer i, ind, val
if (t .eq. 1) then
val = 0
do 100 i = 1,3
if (a(i) .gt. val) then
val = a(i)
ind = i
endif
100
continue
else
val = 256
do 200 i = 1, 3
if (a(i) .lt. val) then
val = a(i)
ind = i
endif
200
continue
endif
maxmin = ind
end
subroutine normalize(arr, a, b)
integer arr(3)
integer a, b, i
do 100 i = 1, 3
arr(i) = arr(i) * b / a
100
continue
end
program norm
integer arr(3)
data arr /121, 221, 56/
integer maxValInd, minValInd, maxVal
maxValInd = maxmin(arr, 1)
maxVal = arr(maxValInd)
call normalize(arr, maxVal, 256)
minValInd = maxmin(arr, 2)
print *, 'Range is ', arr(minValInd), '
to ', arr(maxValInd)
end