Javatpoint Logo
Javatpoint Logo

Q. Program to print the elements of an array present on even position.

Explanation

In this program, we need to print the element which is present in even position.

Even positioned element can be found by traversing the array and incrementing the value of i by 2.

Program to print the elements of an array present on even position

In the above array, elements on even position are b and d.

Algorithm

  1. Declare and initialize an array.
  2. Calculate the length of the declared array.
  3. Loop through the array by initializing the value of variable "i" to 1 (because first even positioned element lies on i = 1) then incrementing its value by 2, i.e., i=i+2.
  4. Print the elements present in even positions.

Solution

Python

Output:

Elements of given array present on even position: 
2
4

C

Output:

Elements of given array present on even position: 
2
4

JAVA

Output:

Elements of given array present on even position: 
2
4

C#

Output:

Elements of given array present on even position: 
2
4

PHP

Output:

Elements of given array present on even position: 
2
4

Next Topic#




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA