Exercise
Array Of Even Numbers
Objective
Write a C# program to ask the user for 10 integer numbers and display the even ones.
Write Your C# Exercise
C# Exercise Example
using System; // Import the System namespace for basic functionality
class Program // Define the main class
{
static void Main() // The entry point of the program
{
// Declare an array to store 10 integers
int[] numbers = new int[10];
// Ask the user to input 10 integer numbers
Console.WriteLine("Please enter 10 integer numbers:");
// Loop to input 10 numbers
for (int i = 0; i < 10; i++)
{
Console.Write($"Enter number {i + 1}: ");
numbers[i] = Convert.ToInt32(Console.ReadLine()); // Store each number in the array
}
// Display the even numbers from the array
Console.WriteLine("\nThe even numbers are:");
foreach (int num in numbers)
{
if (num % 2 == 0) // Check if the number is even
{
Console.WriteLine(num); // Print the even number
}
}
}
}
Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.
In this C# exercise, you are asked to write a program that asks the user for 10 real numbers and displays the average of the positive ones and the average of t...
In this C# exercise, you are asked to write a program that asks the user for several numbers (until they enter the word "end") and then displays the sum of the...
In this C# exercise, you are asked to write a program that asks the user for marks for 20 pupils (2 groups of 10, using a two-dimensional array), and then disp...
In this C# exercise, you are asked to create a statistical program that allows the user to perform the following actions: - Add new data - See all data ...
In this C# exercise, you are asked to create a struct to store data of 2D points. The fields for each point will be: - x coordinate (short)
In this C# exercise, you are asked to expand the previous exercise that used a struct to store 2D points. Now, you need to store up to 1,000 points usin...