Practice ยท 4 of 4
Fix: Uninitialized Accumulator
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;
}
``
Difficulty: beginner
Press Submit to check your solution.
Back to lesson: Practice: Warning Forensics