175k views
4 votes
write a program using one-dimensional array that get the smallest input value from the given array. Array size is 10.​

1 Answer

5 votes

Here is an example of a program that uses a one-dimensional array to find the smallest input value from an array of size 10 in Python:

def find_smallest_value(arr):

smallest = arr[0] #initialize the first element of array as the smallest

for i in range(1, len(arr)): # start the loop from 1 as we already have the first element as the smallest

if arr[i] < smallest:

smallest = arr[i]

return smallest

arr = [5, 2, 8, 9, 1, 3, 4, 6, 7, 10]

print("The smallest value in the array is:", find_smallest_value(arr))

This program defines a function find_smallest_value() that takes an array as an input. Inside the function, it initializes the first element of the array as the smallest. Then it uses a for loop to iterate through the array, starting from the second element. For each element, it checks if the current element is smaller than the current smallest value. If it is, it updates the smallest value. After the loop is finished, it returns the smallest value. In the last line, we call the function and pass the array and print the result.

You can change the elements of the array and test it again to see the result.

User VladN
by
7.4k points