Practice · 4 of 4
Fix: Uninitialized Accumulator
CHALLENGE
Difficulty: beginner+25 XP
sum_evens(const int *a, int n) reads total before initializing it. Fix the function so it returns the sum of even elements.
``c
int sum_evens(const int *a, int n) {
int total;
for (int i = 0; i < n; i++)
if (a[i] % 2 == 0) total += a[i];
return total;
}
``
Press Submit to check your solution.
Back to lesson: Practice: Warning Forensics