Bill Cunningham wrote:
>  
>
> I want to write a function to take so many numbers (doubles) and divide
> their total number (int) and get a arithmetic average. This probably 
> sounds
> simple to all the C pros here but here's my parameter.
>
> double Sma (double *, int);
>
> That's the prototype I have. The thing is I want to enter as many 
> number as
> I want, two decimals to the right of the . or %.2f\n as printf would 
> put it.
> I don't want a buffer overflow but I can take the numbers I put in a 
> divid
> them by the second parameter. To make things more complex I could write
> double Sma (double *) and let the body of the function see how many 
> args are
> entered. For this the for or while statements are going to be needed 
> right?
>
> Bill
>
> 
I'm confused as to what the problem is.

double Sma(double *ds, int size)
{
    double res = 0;
    for (int i = 0; i < size; i++)
       res += ds[i];

    return ds / (double)size;
}

Reply via email to