求大佬帮忙解决下将一个数插入已经排好序的数组中,然后按照原来的规律输出,看看我的代码错在哪
#include<stdio.h>#include<stdlib.h>
int main(){
int i, j, tra1, tra2,number=0,end;
int a[10] = { 1, 4, 9, 11, 20, 31, 40, 51, 66 };
printf("original arry is:\n");
for (i = 0; i < 9; i++)
{
printf("%3d", a[i]);
}
printf("\n");
printf("please insert a number\n");
scanf_s("%d", &number);
end = a[8];
if (number>end)
{
a[9] = number;
}
else
{
for (i = 0; i < 9; i++)
{
if (a[i]>number)
{
tra1 = a[i];
a[i] = number;
}
for (j = i + 1; j < 10; j++)
{
tra2 = a[j];
a[j] = tra1;
tra1 = tra2;
}
break;
}
}
for (i = 0; i < 10; i++)
{
printf("%3d", a[i]);
}
system("pause");
}