126k views
4 votes
Write a program that prompts a user to enter the number of elements to store in an array. Then prompt the user to enter all the numbers stored in the array.

The program should then cycle through the array to see if any numbers are divisible by 5. If any number is divisible by 5 print out which ones are and identify them in the output.

User Jirune
by
7.2k points

1 Answer

3 votes

Answer:

Here's an example of a program that does what you've described:

# Get the number of elements in the array

n = int(input("Enter the number of elements to store in the array: "))

# Initialize the array

arr = []

# Get the elements of the array from the user

print("Enter the elements of the array:")

for i in range(n):

arr.append(int(input()))

# Print out which numbers are divisible by 5

print("The following numbers are divisible by 5:")

for i, x in enumerate(arr):

if x % 5 == 0:

print(f"{i}: {x}")

This program will first prompt the user to enter the number of elements in the array. It then initializes an empty array and prompts the user to enter each element of the array. Finally, it loops through the array and prints out the index and value of any element that is divisible by 5.

Step-by-step explanation:

User Euskalduna
by
7.1k points