current position:Home>After entering two indefinite length arrays and sorting them, merge and sort the two arrays again

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

2022-02-02 18:18:25 CSDN Q & A

img

img

img


Why is the last printed merged array 0




Refer to the answer 1:

tail In the previous operation -- 了




Refer to the answer 2:



Refer to the answer 3:
#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;    }

img




Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021818233977.html

Random recommended