- Course
- Arrays
- Search even numbers
Search even numbers
Last updated:
8/23/2020
⁃
Difficulty:
Intermediate
Write a program in C# that asks the user for 10 integers to store them in an array of integers and show only even integers.
Input
3
5
2
4
3
1
8
10
6
4
Output
2 4 8 10 6 4
Solution
using System;
public class SearchEvenNumbers
{
public static void Main(string[] args)
{
int total = 10;
int[] numbers = new int[total];
for (int i = 0; i < total; i++)
{
numbers[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < total; i++)
{
if (numbers[i] % 2 == 0)
{
Console.Write("{0} ", numbers[i]);
}
}
}
}