home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / p4_17bs.seq < prev    next >
Encoding:
Text File  |  1990-04-16  |  514 b   |  25 lines

  1. \ Balraj Sidhu   Set: 14D4
  2. \ Comp 462 - Forth
  3. \ Date: April 16, 1990
  4. \ Problem 4.17
  5.  
  6.  
  7. create data  20 allot
  8.  
  9.  
  10. \ leaves the number of non zero items k in the array data on the stack.
  11. : count-data ( -- k )
  12.         0 20 0 do i data + c@
  13.         if 1+
  14.         then loop ;
  15.  
  16. \ sums the non zero data values
  17. : sum-data ( -- sum )
  18.         0 20 0 do i data + c@ + loop ;
  19.  
  20. \ prints the average of the non 0 values.
  21. : average-data ( -- )
  22.         cr ." The average is: " sum-data count-data / . cr ;
  23.  
  24.  
  25.