0

Help please

I’ve been stuck on this question for weeks. Can anyone help? The program you are given takes 5 numbers as input and stores them in an array. Complete the program to go through the array and output the the sum of even numbers. Sample Input 10 890 15 3699 14 Sample Output 914 Hint An integer is even if it is divisible by two, so it means that n number is even if n%2 equals 0. What I have so far: static void Main(string[] args) { int[] numbers = new int[5]; int count = 0; while (count <5) { numbers[count] = Convert.ToInt32(Console.ReadLine()); count++; } //your code goes here int x = 0; foreach(int sum in numbers) { if (sum % 2 == 0) { x += sum; Console.WriteLine(x ); }

22nd Mar 2021, 8:24 PM
Brent Tyson
Brent Tyson - avatar
5 Respostas
+ 8
Brent Tyson Print x outside the loop
22nd Mar 2021, 8:27 PM
A͢J
A͢J - avatar
+ 2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int[] numbers = new int[5]; int count = 0; int sum = 0; while (count <5) { numbers[count] = Convert.ToInt32(Console.ReadLine()); count++; } //your code goes here for (int i=0;i<numbers.Length;i++) { if(numbers[i]%2==0) sum +=numbers[i]; } Console.WriteLine(sum); } } }
20th Feb 2023, 2:27 PM
Guy Martial KEYOU
0
🅘🅜 🅰🅹 !!! thank you. it worked.
22nd Mar 2021, 8:29 PM
Brent Tyson
Brent Tyson - avatar
0
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int[] numbers = new int[5]; int count = 0; while (count <5) { numbers[count] = Convert.ToInt32(Console.ReadLine()); count++; } //your code goes here int x = 0; foreach (int sum in numbers) { if (sum % 2 == 0) { x += sum; } } Console.WriteLine(x); } } }
2nd Jun 2023, 11:26 AM
K P Praveen
K P Praveen - avatar
0
class Program { static void Main(string[] args) { int[] numbers = new int[5]; int count = 0; while (count <5) { numbers[count] = Convert.ToInt32(Console.ReadLine()); count++; } //your code goes here int sum = 0; foreach (int i in numbers) { if(i % 2 == 0) { sum = sum + i; } } Console.WriteLine(sum); } }
11th Jun 2023, 7:14 PM
Mohammed Safaf PT
Mohammed Safaf PT - avatar