+ 1
The code works but repeats sum
I was practicing code coach on arrays and I have got sum right but the problem is that the sum is repeated after every step for example Sample input: 1 2 3 4 5 Output: 02266 Expected: 6 https://code.sololearn.com/c071RM5477kI/?ref=app
1 Answer
+ 4
Write print statement outside loop.
for (int i = 0; i<5 ; i++) {
if (numbers[i]%2==0){
sum += numbers[i];
} //if end
} //loop ends
Console.Write(sum);
hope it helps.