The task is to find the sum of the elements located between the first and second negative elements, but for some reason, a large negative number is displayed instead of an answer.
int i, k, s = 0, a[10]; for(int i = 0; i<n; i++) if(a[i] < 0) { k = i; break; } { for(i = k + 1;i<n;i++) s += a[i]; }
n
and the array itself? - Yuriy Orlova
not initialized, its elements refer to random addresses, because of this, the values themselves are unpredictable. What withn
is not at all clear. - Bars