Program to print the elements of an array present on odd position in Python

Program to print the elements of an array present on odd position in Python. This program contains array initialisation, print statement and for loop. This is useful for beginners, class 11, 12 and B Tech computer science students.

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

What is an Array ?

An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together.

What is to be done in this program :

In this program, we need to print the element which is present on odd position. Odd positioned element can be found by traversing the array and incrementing the value of i by 2.

Python program to print the elements of an array present on even position

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

Source code :

arr = [1, 2, 3, 4, 5];     
     
print("Elements of given array present on odd position: ");    
    
for i in range(0, len(arr), 2):    
    print(arr[i]);

Download Source code:

Explanation of source code :

step 1:Initialize array
arr = [1, 2, 3, 4, 5];
print(“Elements of given array present on odd position: “);
step 2: Loop through the array by incrementing the value of i by 2
step 3:Here, i will start from 0 as first odd positioned element is present at position 0.
for i in range(0, len(arr), 2):
print(arr[i]);

Output :

 RESTART: C:/csstudy/source code file 2/Program to print the elements of an array present on odd position in Python.py 
Elements of given array present on odd position: 
1
3
5

Output Explanation:

Elements of given array present on odd position:
1
3
5
The elements at the odd positions are calculated and printed out . The array is defined in the program itself. Array 1 =[1,2,3,4,5]
The odd number is shown in the output .

Conclusion:

The program is running fine.

Thank you for reading, learning and downloading source code of Program to print the elements of an array present on odd position in Python. This program contains array initialisation, print statement and for loop. This is useful for beginners, class 11, 12 and B Tech computer science students. for more programs like this , click below links :
csstudy.in/category/python-programs/
Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study
Computer Science Practical file for class 12 Term-2 – CS Study
Python Projects for Class 12 with Source Code (Mysql Connectivity) – CS Study

Leave a Comment

Your email address will not be published.