Pot Pourri

Authors

Publication

Date

Pages

BASIC Terms

This method of using recursive DEF FN to obtain sums was discussed in a TS Survival column in COMPUTER SHOPPER. It is fast and handy in some applications.

1 REM The method below of using  recursive DEF FN to obtain sums was discussed in a TS Survival  column in COMPUTER SHOPPER. I  don't have the date,unfortunately, but it is fast and handy in some applications.
2 REM added by E.HAMMETT,CHAPEL HILL,N.C.
9 REM The function below calculates the sum of the first n elements of a linear array
10 DEF FN t(a$,n)=VAL (a$+"(n)"+("+FN t(a$,n-1)" AND n>1))
11 REM The function below calculates the sum of squares of the first n elements of a linear array
12 DEF FN s(a$,n)=VAL (a$+"(n)*"+a$+"(n)"+("+FN s(a$,n-1)" AND n>1))
20 DIM v(10): REM set up an array as an example
30 FOR i=1 TO 10: LET v(i)=2: NEXT i: REM put a value in each cell of the array for the example
40 LET sum=FN t("v",10): REM use the function, passing the array name as a string
50 PRINT : PRINT "Sum = ";sum
60 LET sumofsquares= FN s("v",10): REM use the function to obtain squares, passing the array name as a string
70 PRINT "Sum of squares = ";sumofsquares
75 PRINT '"LIST THE PROGRAM TO STUDY THE ";"USE OF USER DEFINED FUNCTIONS TO";"OBTAIN THESE TOTALS."
80 STOP
90 SAVE "recurfn" LINE 1

Products

 

Media

 

Image Gallery

Source Code

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top