Group
C# Arrays, Structures and Strings
Objective
1. Ask the user to enter 10 integer numbers.
2. Store the numbers in an array.
3. Iterate through the array to find the even numbers.
4. Display only the even numbers on the screen.
5. Ensure the program handles user input properly.
Write a C# program to ask the user for 10 integer numbers and display the even ones.
Example C# Exercise
Show C# Code
using System;
class Program
{
static void Main()
{
// Define an array to store 10 integers
int[] numbers = new int[10];
// Prompt the user to enter 10 numbers
Console.WriteLine("Enter 10 integer numbers:");
for (int i = 0; i < numbers.Length; i++)
{
Console.Write($"Number {i + 1}: ");
numbers[i] = Convert.ToInt32(Console.ReadLine());
}
// Display even numbers
Console.WriteLine("\nEven numbers from the list:");
foreach (int num in numbers)
{
if (num % 2 == 0)
{
Console.Write(num + " ");
}
}
Console.WriteLine(); // Move to the next line after displaying even numbers
}
}
Output
Enter 10 integer numbers:
Number 1: 3
Number 2: 10
Number 3: 15
Number 4: 8
Number 5: 23
Number 6: 6
Number 7: 19
Number 8: 4
Number 9: 11
Number 10: 2
Even numbers from the list:
10 8 6 4 2