Q:

Print all Even numbers from array of integers using C# program

belongs to collection: C# Basic Programs | array programs

0

Given array of integers and we have to print all EVEN numbers.

For example we have list of integers:

18, 13, 23, 12, 27

18 is properly divisible by 2, So it is a even number.
13 is not properly divisible by 2, so it is not a even number.
23 is not properly divisible by 2, so it is not a even number.
12 is properly divisible by 2, So it is a even number.
27 is not properly divisible by 2, so it is not a even number.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main()
		{
			int i       = 0;
			//declare array of integers
			int[] arr   = new int[5];

			//reading elements
			Console.WriteLine("Enter array elements : ");
			for (i = 0; i < arr.Length; i++)
			{
				Console.Write("Element[" + (i + 1) + "]: ");
				arr[i] = int.Parse(Console.ReadLine());
			}

			//checking and printing list of EVEN integers
			Console.WriteLine("List of even numbers : ");
			for (i = 0; i < arr.Length; i++)
			{
				//condition for EVEN number
				if (arr[i] % 2 == 0)
				Console.Write(arr[i] + " ");
			}
			Console.WriteLine();
		}
	}
}

Output

Enter array elements :
Element[1]: 10
Element[2]: 11
Element[3]: 12
Element[4]: 13
Element[5]: 14
List of even numbers :
10 12 14

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | array programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Print all Odd numbers from array of integers using... >>
<< Find leap years form array of integers using C# pr...