Can u guyz help me for this problem

Write a function that given an array, returns both the minimum and maximum values in the list. Your main program should allow the user to enter space-separated numbers as test lists, until a blank line is entered.
Sample output of the program:
List: 3 6 9 2 4 6
min =2, max = 9

List:7
min =2, max = 9

List:

Help me guys

1 Like

In Python you can directly use min() and max() function for this task.
or Go for iterative method:

  1. assign min = max = List[0]
  2. for each element in List:
    if element < min : min = element
    if element > max: max = element
  3. print(min,max)

void min_max(int arr[], int n)
{
int min,max;
min=max=arr[0];
for(int i=1; i<n; i++){
if(min>arr[i])
min = arr[i];
if(max<a[i])
max=a[i];
}
printf("Minimum ",min);
printf("Maximum ",max);
}