home *** CD-ROM | disk | FTP | other *** search
- /* Listing 7 -- a fast mean function in Turbo C */
-
- #include <stdio.h>
- void mean(double *list);
-
- main()
- {
- double list[7000]; /* Create a list of reals to process */
- double i; /* The time to do this isn't included */
- /* in the benchmark. */
-
- for(i = 1; i < 7000; i++)
- list[i]=i;
- mean(list); /* Call subroutine, mean */
- /* to calculate. */
- }
- void mean(double *list) {
- int i;
- double x = 0, z;
-
- puts("start"); /* Start timing here */
- for(i = 1; i < 6999; i++){
- x = list[i] + x; /* Add each element of */
- } /* the array. */
- z = x/i; /* Divide by count */
- printf("%f\n",z); /* Print result */
- }