IBM SC34-5764-01 User Manual
Page 91
Advertising

/******************************* REXX ********************************/
/*
This function receives a list of numbers, adds them, computes
*/
/*
their average, and returns the average to the calling program.
*/
/*********************************************************************/
ARG numlist
/* receive the numbers in a single variable
*/
sum = 0
/* initialize sum to zero
*/
DO n = 1 TO WORDS(numlist)
/* Repeat for as many times as there
*/
/* are numbers
*/
number = WORD(numlist,n)
/* Word #n goes to number
*/
sum = sum + number
/* Sum increases by number */
END
average = sum / WORDS(numlist)
/* Compute the average
*/
RETURN average
Figure 44. Possible Solution
Writing Subroutines and Functions
Chapter 6. Writing Subroutines and Functions
69
Advertising