插入一个数到排列好的数组里

img

img

img

img


我前面把数组排列好了但是后面插入一个数的时候程序没反应

水题居然没人答?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    int a[21], i, j, c, b, t1, t2;
    srand((int)time(NULL));
    for(i=0; i<20; i++)
    {
        a[i] = rand() % 90 + 10;
    }
    for(i=0; i<20; i++)
    {
        for(j=0; j<19-i; j++)
        {
            if(a[j] > a[j+1])
            {
                c=a[j];
                a[j]=a[j+1];
                a[j+1]=c;
            }
        }
    }
    for(i=0; i<20; i++)
    {
        printf("%d ", a[i]);
    }
    printf("\n");
    printf("输入任意一个2位的整数:\n");
    scanf("%d", &b);
    if(b > a[19])
        a[20] = b;
    else{
        for(i=0; i<20; i++)
        {
            if(a[i] > b)
            {
                t1 = a[i];
                a[i] = b;
                for(j=i+1; j<21; j++)
                {
                    t2 = a[j];
                    a[j] = t1;
                    t1 = t2;
                }
                break;
            }
        }
    }
    for(i=0; i<21; i++)
    {
        printf("%d ", a[i]);
    }
    return 0;
}