The code works but repeats sum | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

8th Jul 2022, 9:48 AM
Shivansh Mourya
Shivansh Mourya - avatar
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.
8th Jul 2022, 10:07 AM
Jayakrishna 🇮🇳