Javatpoint Logo
Javatpoint Logo

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

Explanation

In this program, we need to print the elements of the array which are present in odd positions. This can be accomplished by looping through the array and printing the elements of an array by incrementing i by 2 till the end of the array is reached.

Program to convert a given binary tree to doubly linked list

In the above array, the elements which are on odd positions are a, c and e.

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 0 then incrementing its value by 2, i.e., i=i+2.
  4. Print the elements present in odd positions.

Solution

Python

Output:

Elements of given array present on odd position: 
1
3
5

C

Output:

Elements of given array present on odd position: 
1
3
5

JAVA

Output:

Elements of given array present on odd position: 
1
3
5

C#

Output:

Elements of given array present on odd position: 
1
3
5

PHP

Output:

Elements of given array present on odd position: 
1
3
5

Next Topic#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA