int sum(int *p, int n)
{
int i, s=0;
for(i = 0; i < n; i++)
{
if(i % 2 == 0)
s += *p;
< p>p++;}
return s;
} Because the index starts from 0, odd subscripts appear as even numbers.
If I understand correctly, you want the index to be an odd number. Please change the sentence if(i % 2 == 0) to if(i % 2 != 0)