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.
In the above array, the elements which are on odd positions are a, c and e.
Algorithm
- Declare and initialize an array.
- Calculate the length of the declared array.
- Loop through the array by initializing the value of variable "i" to 0 then incrementing its value by 2, i.e., i=i+2.
- Print the elements present in odd positions.
Input:
arr = [1, 2, 3, 4, 5]
Output:
Elements of given array present on odd position:
1
3
5
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: