# After entering two indefinite length arrays and sorting them, merge and sort the two arrays again

2022-02-02 18:18:25

Why is the last printed merged array 0

tail In the previous operation -- 了

``#include <stdio.h>void Sort(int t[], int n){    int i;    for ( i = 0; i < n - 1; ++i)    {        int end = i;        int tem = t[end + 1];        while (end >= 0)        {            if (tem < t[end])            {                t[end + 1] = t[end];                end--;            }            else            {                break;            }            }        t[end+1] = tem;    }}void Printarr(int t[],int n){    int j=0;    while(j<n)    {        printf("%d ",t[j]);        j++;    }    printf("\n");}int main(){        int j=0;        int n1,n2;        printf(" Please enter an array p1[] size ：");        scanf("%d",&n1);        int p1[n1];        while(j<n1)        {            scanf("%d",&p1[j]);            j++;        }        Sort(p1,n1);         printf(" After ordering ");Printarr(p1,n1);                        printf(" Please enter an array p2[] size ：");        scanf("%d",&n2);        int p2[n2];        j=0;        while(j<n2)        {            scanf("%d",&p2[j]);            j++;        }        Sort(p2,n2);        printf(" After ordering ");Printarr(p2,n2);                int n3=n1+n2;        int p3[n3];                j=0;        while(j<n1)        {            p3[j]=p1[j];            j++;        }        while(j<n3)        {            p3[j]=p2[j-n1];            j++;        }                printf(" After the merger ");Printarr(p3,n3);        Sort(p3,n3);        printf(" After ordering ");Printarr(p3,n3);        return 0;    }``