I am using C and I have an array t[]
I wrote a for loop but the answer is wrong.
Please help me catch the error. My code is:
for(j = 0; j < tags; j++)
{
for(k = j; k < nb_of_subscribers*tags; k = k+tags)
{
avr[j] = (float)(avr[j]+t[k]);
}
printf("avr[j]:%f", avr[j]);
}
Actually , the values of t[] are read incorrectly in the for loop i don’t know why . If i use a for loop only to printf the values of the array t the response is correct otherwise(in the for loop)it is incorrect
Thank you.
You should set
avr[j]to 0 before starting your iterative sum: