Write a program that declares an array of size 5. Input values in the array from user, and then display allvalues of array
Question
Write a program that declares an array of size 5.
Input values in the array from user, and then display all values of array.
Solution
Sure, here is a simple program in Python that accomplishes this:
# Declare an array of size 5
arr = [0]*5
# Input values in the array from user
for i in range(5):
arr[i] = int(input("Enter a number: "))
# Display all values of array
for i in range(5):
print(arr[i])
This program first declares an array of size 5. Then it uses a for loop to iterate over each element in the array, prompting the user to input a value for each element. Finally, it uses another for loop to print out each value in the array.
Similar Questions
Initialize an array/list with five integers. Write a program to find the sumand average of these numbers
How do you access the fifth element of an array named numbers?numbers[4];numbers[5];numbers[3];numbers[0];
Write a program in C++ that takes age of five persons and then just display the age of each person usingarrays
Given a 2D integer array size (4, 5) with name input_?Print elements of highlighted matrix Output Format :
Write a program to print the following output: [3] 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.