Recursive implementation of merge sort
I've slightly reorganised your code to make it easier to follow.

void merge_parts(int arr[], int length)
{
    /*
    Sorts into increasing order
    For decreasing order change the comparison in for-loop
    */
    int ans[length];
    //This for and next if-else puts the merged array into temporary array ans
    //in a sorted manner
    int mid = length/2;
    int i = 0, k = 0, j = mid;
    while (i &lt; mid &amp;&amp; j &lt; length){
        ans[k++] = (arr[i] &lt; arr[j]) ? arr[i++] : arr[j++];
    }

    // Only one of the two loops will apply
    while(j &lt; length){
        ans[k++] = arr[j++];
    }
    while(i &lt; mid){
        ans[k++] = arr[i++];
    }

    //This for-loop puts array ans into original array arr
    for(int i = 0; i &lt; length; i++){
        arr[i] = ans[i];
    }
}

void merge_sort(int arr[], int length)
{
    if(length &gt; 1)
    {
        int mid = length/2;
        merge_sort(arr,     mid);
        merge_sort(arr+mid, length - mid);
        merge_parts(arr, length);
    }
}

int main()
{
    int length;
    for (;;)
    {
        printf("\nEnter a positive length: ");
        scanf("%d", &amp;length);
        printf("\nYou entered length = %d\n", length);
        if (length&gt;=1) break;
    }

    int *arr = malloc(sizeof(int) * length);
    if (!arr)
    {
        perror("The following error occurred");
        exit(-1);
    }

    for (int i = 0; i &lt; length; i++){
        scanf("%d", &amp;arr[i]);
    }

    merge_sort(arr, length);

    for (int i = 0; i &lt; length; i++){
        printf("%d ", arr[i]);
    }

    free(arr);
    return 0;
}


Then for the only optimisation I can think of, you could avoid some copying : when j &lt; length after the main loop, it corresponds to a situation where the end of arr is already sorted in the right place. Thus, you don't need to copy it from arr to ans and then from ans to arr.

int mid = length/2;
int i = 0, k = 0, j = mid;
while (i &lt; mid &amp;&amp; j &lt; length){
    ans[k++] = (arr[i] &lt; arr[j]) ? arr[i++] : arr[j++];
}

while(i &lt; mid){
    ans[k++] = arr[i++];
}

//This for-loop puts array ans into original array arr
for(i = 0; i &lt; j; i++){
    arr[i] = ans[i];
}