find min and max in array python code example

Example 1: find min and max in array c++

#include<iostream>

using namespace std;

public void getMax_MinValue(int arr[])
{
    int max, min;

    max = arr[0];
    min = arr[0];
    for (int i = 0; i < sizeof(arr); i++)
    {
        if (max < arr[i])
            max = arr[i];
        else if (min > arr[i])
            min = arr[i];
    }

    cout << "Largest element : " << max;
    cout << "Smallest element : " << min;
 
}

Example 2: python get min from array

>>> arr = [1, 3.14159, 1e100, -2.71828]
>>> min(arr)
-2.71828

Example 3: min in a list python

li=[0,70,7,89]
min(li)
#gives the min value 0

Example 4: how to find min value in array in python

use sort and return first element

Tags:

Cpp Example