On Tue, Jul 21, 2009 at 2:40 AM, billcu34<[email protected]> wrote:
>> double Sma(double *ds, int size)
>> {
>>     double res = 0;
>>     for (int i = 0; i < size; i++)
>>        res += ds[i];
>>
>>     return ds / (double)size;
>> }
>
> My compiler complained about the ds in the return statement. It wanted this I 
> guess 'cause I changed it and it accepted.
>
> return *ds/(double) size;

It should in fact read
   return res/size;

i.e. the sum divided by the number of items (your solution, while
fixing the warning, only divides the first number by the number of
items.)

The (double) cast is, at best documentary, at worst redundant.

> It also didn't like the for statement saying int i. I changed it to this.
>
> int i,res=0;
> for(i=0;i<size;i++)

You have an old compiler - you have the right fix here.

> I don't know what kind of errors these are but I think they have something to 
> do with C89 and ISO C.

-- 
PJH

http://shabbleland.myminicity.com/com
http://www.chavgangs.com/register.php?referer=9375

Reply via email to