I have small problem with my home task. I have to create a method that sums an array, but with specific, given step. I did something like this:
int sum_step(int t[], int size, int step)
{
int i;
int sum = 0;
for(i=0; i < size; i+step)
{
sum += t[i];
}
return sum;
}
and console returns warning:
warning: expression result unused
[-Wunused-value]
i + step;
~ ^ ~~~~
Someone knows what is wrong? Thank in advance!
In following for
statement the third expression i+step
does nothing.
for (i = 0; i < size; i + step)
You probably want i
to be incremented by step
after each iteration so you should write this:
for (i = 0; i < size; i += step)