#include
#include
#define N 11
main()
{
int i,j,t,number,a[N]={1,2,4,6,8,9,12,15,149,156};
a[10]=0;
printf("please enter an integer to insert in the array:\n");
scanf("%d",&number);
printf("The original array:\n");
for(i=0;i
printf("\n");
for (i=N-2;i>=0;i--)
{
if(number>a[0])
{
if (number>a[i])
{
for (j=N-1;j>i+1;j--)
{
a[j]=a[j-1];
}
a[i+1]=number;
break;
}
}
else
{
for(j=N-1;j>0;j--)
a[j]=a[j-1];
a[0]=number;
break;
}
}
printf("The result array:\n");
for(i=0;i
printf("\n");
}
我看楼上 在输入数字大于 原数组最大数跟输入数字小于原数组最小数的时候,会出错,改了下。
你问题没说清楚,插入一个数后然后要怎么样???说清楚了我帮你改!
补充:
#include
#include
#define N 11
main()
{
int i,j,t,number,a[N]={1,2,4,6,8,9,12,15,149,156};
printf("please enter an integer to insert in the array:\n");
scanf("%d",&number);
printf("The original array:\n");
for(i=0;i
printf("\n");
for (i = 0; i < N-1; i++)
{
if (number >= a[i] && number <= a[i+1])
{
for (j=N-2; j >= i+1; j--)
a[j+1] = a[j];
a[i+1]=number;
break;
}
}
printf("The result array:\n");
for(i=0;i
printf("\n");
}
#include
#define
N
11
void
main()
{
int
i,j,number,a[N]={1,2,4,6,8,9,12,15,149,156};
printf("please
enter
an
integer
to
insert
in
the
array:\n");
/**********FOUND**********/
scanf("%d",&number)
;
printf("The
original
array:\n");
for(i=0;i
printf("\n");
/**********FOUND**********/
i=0;
while
(i
i++;
for(j=N-1;j>=i;j--)
/**********FOUND**********/
a[j]=a[j-1];
/**********FOUND**********/
a[i]=number;
printf("The
result
array:\n");
for(i=0;i
printf("\n");
}
#include
#define N 11
void main()
{
int i,j,number,a[N]={1,2,4,6,8,9,12,15,149,156};
printf("please enter an integer to insert in the array:\n");
/**********FOUND**********/
scanf("%d",&number) ;
printf("The original array:\n");
for(i=0;i
printf("\n");
/**********FOUND**********/
i=0;
while (i
for(j=N-1;j>=i;j--)
/**********FOUND**********/
a[j]=a[j-1];
/**********FOUND**********/
a[i]=number;
printf("The result array:\n");
for(i=0;i
printf("\n");
}