Microsoft KB Archive/106700: Difference between revisions
From BetaArchive Wiki
(importing KB archive) |
m (Text replacement - "<" to "<") |
||
(One intermediate revision by the same user not shown) | |||
Line 31: | Line 31: | ||
TheArray[10] = 10 | TheArray[10] = 10 | ||
TheAvg =Aavg(@TheArray,10) | TheAvg =Aavg(@TheArray,10) | ||
WAIT WINDOW | WAIT WINDOW "The average of the array is " + ALLTRIM(STR(TheAvg,8,2)) | ||
RETURN | RETURN | ||
Line 47: | Line 47: | ||
STORE 0 TO Atotal, Avg | STORE 0 TO Atotal, Avg | ||
STORE 1 TO Acount | STORE 1 TO Acount | ||
DO WHILE Acount | DO WHILE Acount <= Aelements | ||
Atotal = Atotal + Aname[Acount] | Atotal = Atotal + Aname[Acount] | ||
Acount = Acount + 1 | Acount = Acount + 1 |
Latest revision as of 15:05, 20 July 2020
Function to Compute Average of the Elements in an ArrayID: Q106700 The information in this article applies to:
SUMMARYThe user-defined function (UDF) shown below uses a DO WHILE loop to sum the elements of the passed array and then divides the total by the number of elements in the array to obtain the average. MORE INFORMATIONCLEAR SET CURSOR OFF SET TALK OFF DECLARE TheArray[10] TheArray[1] = 1 TheArray[2] = 2 TheArray[3] = 3 TheArray[4] = 4 TheArray[5] = 5 TheArray[6] = 6 TheArray[7] = 7 TheArray[8] = 8 TheArray[9] = 9 TheArray[10] = 10 TheAvg =Aavg(@TheArray,10) WAIT WINDOW "The average of the array is " + ALLTRIM(STR(TheAvg,8,2)) RETURN * Function.....: AAVG * Notes........: This function computes the average of the elements * in an array. * Parameters: Aname - The name of an array containing * numeric elements to average. * Aelements - The numeric of elements to average. FUNCTION AAVG PARAMETERS Aname, Aelements STORE 0 TO Atotal, Avg STORE 1 TO Acount DO WHILE Acount <= Aelements Atotal = Atotal + Aname[Acount] Acount = Acount + 1 ENDDO RETURN(Atotal/Aelements)
Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b KBCategory: kbprg kbcode KBSubcategory: FxprgGeneral |
Last Reviewed: June 27, 1995 |