news:c764e4b7-1662-44cc-808e-21eab51912c4@b14g2000yqd.googlegroups.com...
don't post fragments. Some people can get away with it
but you hack things about too much.
double Sma (double *num) {
int count=*num,i;
what value does i have?
why did you zero the first element of num?
why is i decrementing?
you are using the first element as the sum?
I think *num is being used for too many things.
Keep It Simple. Use another variable for the sum.
}
return *num/count;
}
Has the i been previously declared?
well?
The for statement I understand as a dereference.
there are derefrences in there. I doubt you understand though
After trying to remember what I think I once knew and looking it up for the
nth time I think something like the above is what I would come up with. I
will see if it compiles.
your layout is horrid
double sma (int count, double *num)
{
int i;
double sum = 0;
/* don't try and be clever (you aren't).
write simple code that does the job in a straight-forward way */
for (i = 0; i < count; i++)
{
sum += *(num + i);
/* or easier to understand
sum += num
;
*/
}
return sum / count;
}
don't use num for three different things (are you short
of memory or something?). don't count backwards in your
for-loop. use array notation when it is clearer.
Don't try be clever