Given an array of numbers, write a program to find the median value.
To find the median value of an array of numbers, you need to do the following:

1. Sort the array in ascending order
2. Check if the array length is an odd number or an even number
3. If the length is an odd number, the median is the element in the middle of the sorted array
4. If the length is an even number, calculate the median by finding the average of two middle elements in the sorted array

Here's the code in Python that finds the median value of the given array:

```python
def find_median(arr):
    # Sort the array
    arr = sorted(arr)
    n = len(arr)
    # Check if the length is odd or even
    if n % 2 == 0:
        # Get the average of two middle elements
        return (arr[n//2 - 1] + arr[n//2]) / 2
    else:
        # Get the middle element
        return arr[n//2]
```

Using the above function, we can find the median value of the given input array:

```python
input_arr = [10, 20, 30, 40]
median = find_median(input_arr)
print(f"The median value of the given array is: {median}")
```

Output: The median value of the given array is: 25.0.
[10, 20, 30, 40]
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.

### Instruction:
Given an array of numbers, write a program to find the median value.

### Input:
[10, 20, 30, 40]

### Response:
To find the median value of an array of numbers, you need to do the following:

1. Sort the array in ascending order
2. Check if the array length is an odd number or an even number
3. If the length is an odd number, the median is the element in the middle of the sorted array
4. If the length is an even number, calculate the median by finding the average of two middle elements in the sorted array

Here's the code in Python that finds the median value of the given array:

```python
def find_median(arr):
    # Sort the array
    arr = sorted(arr)
    n = len(arr)
    # Check if the length is odd or even
    if n % 2 == 0:
        # Get the average of two middle elements
        return (arr[n//2 - 1] + arr[n//2]) / 2
    else:
        # Get the middle element
        return arr[n//2]
```

Using the above function, we can find the median value of the given input array:

```python
input_arr = [10, 20, 30, 40]
median = find_median(input_arr)
print(f"The median value of the given array is: {median}")
```

Output: The median value of the given array is: 25.0.