We already know that an array is data structure where we can store the values of similar data type. In Python there is possibility of using lists instead of arrays. In this post I will show you how to write a python program to find the highest and lowest elements in an array.
#To find highest element in an array
|Highest element in array is: 265|
Firstly we defined a function called “highest” and also we passed parameters ‘arr’ and ‘n’ in to it. Next we are initializing an array ‘arr’ and is stored in variable ‘high’. By using for loop we perform traversing on every element in an array. Here every element in the array is compared with current highest element and then returns the highest element among those compared.This procedure continues until the base condition ‘if arr[i] > high’ becomes true. Now the list of elements is appended to an array and is stored in a variable ‘arr’. The ‘len( )’ method evaluates the length of an array and is allocated to variable ‘n’. The function definition ‘res = highest(arr,n)’ is called and finally prints the output.
Similarly we can also write a python program to find the lowest element in an array. It is shown in below code.
# To find lowest element in an array
|Lowest element in array is: 3.33|