home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / nvdc87 / lcv1n1 / mean3.c < prev    next >
Text File  |  1987-08-12  |  835b  |  28 lines

  1. /* Listing 7 -- a fast mean function in Turbo C */
  2.  
  3. #include <stdio.h>
  4. void mean(double *list);
  5.  
  6. main()
  7. {    
  8.    double list[7000];        /* Create a list of reals to process  */
  9.    double i;                 /* The time to do this isn't included */
  10.                  /* in the benchmark. */
  11.  
  12.    for(i = 1; i < 7000; i++)
  13.    list[i]=i;
  14.    mean(list);               /* Call subroutine, mean  */
  15.                              /* to calculate.          */
  16. }
  17.    void mean(double *list) {
  18.       int i;
  19.       double x = 0, z;
  20.  
  21.       puts("start");            /* Start timing here */
  22.       for(i = 1; i < 6999; i++){
  23.       x = list[i] + x;       /* Add each element of */
  24.    }                         /* the array.          */
  25.    z = x/i;                  /* Divide by count */
  26.    printf("%f\n",z);         /* Print result */
  27. }
  28.