Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

trying to make a function that returns average of an array

$
0
0
I feel like i'm doing the actual function right but i'm not sure how to actually call it to see if it is right

I keep getting an error on the call line.

#include <stdio.h>
#include <stdlib.h>

double arrayAvg(double D[], int len);

int main()
{
        double arr[4] = {1.0, 2.0, 3.0, 4.0};
        
        double value = arrayAvg(arr[], 4);

        printf("%f\n", value);
        
        system("PAUSE");
        return 0;
        
}


double arrayAvg(double D[], int len)
{
       double sum;
       double average;
       
       for(int i=0; i <= len; i++)
       {
              sum += [i];     
       }
       
       average = sum / (double) len;
       return average;
     }


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>