Array of even numbers Learn programming C#



Lesson:

Arrays, Structures and Strings


Exercise:

Array of even numbers


Objetive:

Write a C# program to ask the user for 10 integer numbers and display the even ones.


Code:

using System;
public class exercise74
{
    public static void Main()
    {
        int[] numbers = new int[10];

        for (int i = 0; i < 10; i++)
        {
            Console.Write("Numero {0}= ", i + 1);
            numbers[i] = Convert.ToInt32(Console.ReadLine());
        }

        for (int i = 0; i < 10; i++)
            if (numbers[i] % 2 == 0)
                Console.Write("{0} ", numbers[i]);
    }
}



Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.