Python Array Solution Q5

 Write a program to reverse the elements of an array.


from array import array


# Create an array of integers

original_array = array('i', [1, 2, 3, 4, 5])


# Reverse the array

reversed_array = array('i', reversed(original_array))


# Print the original and reversed arrays

print("Original Array:", original_array)

print("Reversed Array:", reversed_array)



In this program:


The user is prompted to enter the size of the arrays.

Two arrays (array1 and array2) are created using list comprehensions to take user input for each element.

Element-wise addition is performed using the zip() function and a list comprehension.

The arrays and the result are printed.

Users will enter elements for both arrays, and the program will then add corresponding elements together to form the resulting array.


Comments

Popular posts from this blog

Class X Test / Model Paper Chapter No 1 Computer

Inter Board Karachi Guess/Model Papers 2023 (1st year & 2nd year)

Dulla Bhatti Real Hero Of Muslims Rajput