Program to find the minimum (or maximum) element of an arrayGiven an array, write functions to find the minimum and maximum elements in it. Show
C++
Java
Python3
C#
PHP
Javascript
Output: Minimum element of array: 1 Maximum element of array: 1234Time Complexity:O(n) Recursive Solution C++
Java
Python3
C#
Javascript
Output: Min of array: 1 Max of array: 1234Using Library functions: C++
Java
Python3
C#
PHP
Javascript
Output: Minimum element of array: 1 Maximum element of array: 1234
Article Tags :
Recursion School Programming Searching
CBSE - Class 11 school-programming Practice Tags :
Searching Recursion Maximum and minimum of an array using minimum number of comparisonsWrite a C function to return minimum and maximum in an array. Your program should make the minimum number of comparisons. Python to Find Minimum and Maximum Elements of List
1: Python Program to find the Largest and Smallest Number in a List using min() and max() method
# Python Program to find Largest and Smallest Number in a List
NumList = []
Number = int(input("Please enter element length in list "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
print("The Smallest Element in this List is : ", min(NumList))
print("The Largest Element in this List is : ", max(NumList))
After executing the program, the output will be: How many element in list, Please enter num :- 5 Please enter the Value of 1 Element : 500 Please enter the Value of 2 Element : 653 Please enter the Value of 3 Element : 895 Please enter the Value of 4 Element : 565 Please enter the Value of 5 Element : 568 The Smallest Element in this List is : 500 The Largest Element in this List is : 895Recommended:-Python Program to Find Smallest/Minimum of n Numbers 2: Python Program to find the Minimum and Maximum Number in a List with their position using for loop and if statement
# Python Program to find Largest and Smallest Number in a List
# Python Program to find Largest and Smallest Number in a List
NumList = []
Number = int(input("How many element in list, Please enter num :- "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
smallest = largest = NumList[0]
for j in range(1, Number):
if(smallest > NumList[j]):
smallest = NumList[j]
min_position = j
if(largest < NumList[j]):
largest = NumList[j]
max_position = j
print("The Smallest Element in this List is : ", smallest)
print("The Index position of Smallest Element in this List is : ", min_position)
print("The Largest Element in this List is : ", largest)
print("The Index position of Largest Element in this List is : ", max_position)
After executing the program, the output will be: How many element in list, Please enter num :- 5 Please enter the Value of 1 Element : 70 Please enter the Value of 2 Element : 90 Please enter the Value of 3 Element : 60 Please enter the Value of 4 Element : 80 Please enter the Value of 5 Element : 45 The Smallest Element in this List is : 45 The Index position of Smallest Element in this List is : 4 The Largest Element in this List is : 90 The Index position of Largest Element in this List is : 13: Python Program to find the Largest and Smallest Number in a List using sort() method
# Python Program to find Largest and Smallest Number in a List
NumList = []
Number = int(input("How many element in list, please enter num :- "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
NumList.sort()
print("The Smallest Element in this List is : ", NumList[0])
print("The Largest Element in this List is : ", NumList[Number - 1])
After executing the program, the output will be: How many element in list, please enter num :- 5 Please enter the Value of 1 Element : 98 Please enter the Value of 2 Element : 45 Please enter the Value of 3 Element : 63 Please enter the Value of 4 Element : 78 Please enter the Value of 5 Element : 25 The Smallest Element in this List is : 25 The Largest Element in this List is : 984: Python Program to find the position of min and max elements of a list using min() and max() function
# Python Program to find Largest and Smallest Number in a List
NumList = []
Number = int(input("How many element in list, Please enter num :- "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
# min element's position/index
min = NumList.index(min(NumList))
# max element's position/index
max = NumList.index(max(NumList))
# printing the position/index of min and max elements
print("position of minimum element: ", min)
print("position of maximum element: ", max)
After executing the program, the output will be: How many element in list, Please enter num :- 5 Please enter the Value of 1 Element : 5 Please enter the Value of 2 Element : 8 Please enter the Value of 3 Element : 9 Please enter the Value of 4 Element : 4 Please enter the Value of 5 Element : 2 position of minimum element: 4 position of maximum element: 2C Program To Find Maximum & Minimum Element In Array | C Proramsin C Programs Comments Off on C Program To Find Maximum & Minimum Element In Array | C Prorams C program to find the maximum and minimum element in an array – In this article, we will brief in on the many ways to find the maximum and minimum element in an array in C programming. Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself. The ways used in this piece are as follows:
As we all know, arrays are a collection of a bunch of elements in a sequential pattern in a horizontal direction. Arrays form a very important of C programming. As given in the example above, firstly, enter the size of the array that you want to define. The size of the array in the example mentioned is 5. After that, you need to enter the elements of the array. The elements entered in the array are as follows: 1 2 35 0 -1 So, the minimum of the array is -1 and the maximum of the array is 35. Thus, doing the same using multiple methods in C programming is as follows: C++
DownloadRun Code C Exercises: Find the maximum and minimum element in an arrayLast update on December 18 2021 11:49:16 (UTC/GMT +8 hours) |