在一个已按升序排列的数组中插入一个数,插入后,数
#defineN11main(){inti,j,t,number,a[N]={1,2,4,6,8,9,12,15,149,156};printf("pleaseenter...
#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");
/**********FOUND**********/
scanf("%d",&number)
printf("The original array:\n");
for(i=0;i<N-1;i++)
printf("%5d",a[i]);
printf("\n");
/**********FOUND**********/
for(i=N-1;i>=0;i--)
if(number<=a[i])
/**********FOUND**********/
a[i]=a[i-1];
else
{
a[i+1]=number;
/**********FOUND**********/
exit;
}
if(number<a[0]) a[0]=number;
printf("The result array:\n");
for(i=0;i<N;i++)
printf("%5d",a[i]);
printf("\n");
}
程序改错 多谢大侠们 在线等
功能:在一个已按升序排列的数组中插入一个数,插入后,数
组元素仍按升序排列。 展开
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");
/**********FOUND**********/
scanf("%d",&number)
printf("The original array:\n");
for(i=0;i<N-1;i++)
printf("%5d",a[i]);
printf("\n");
/**********FOUND**********/
for(i=N-1;i>=0;i--)
if(number<=a[i])
/**********FOUND**********/
a[i]=a[i-1];
else
{
a[i+1]=number;
/**********FOUND**********/
exit;
}
if(number<a[0]) a[0]=number;
printf("The result array:\n");
for(i=0;i<N;i++)
printf("%5d",a[i]);
printf("\n");
}
程序改错 多谢大侠们 在线等
功能:在一个已按升序排列的数组中插入一个数,插入后,数
组元素仍按升序排列。 展开
5个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#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<N-1;i++)
printf("%5d",a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
我看楼上 在输入数字大于 原数组最大数跟输入数字小于原数组最小数的时候,会出错,改了下。
#include <stdlib.h>
#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<N-1;i++)
printf("%5d",a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
我看楼上 在输入数字大于 原数组最大数跟输入数字小于原数组最小数的时候,会出错,改了下。
展开全部
你问题没说清楚,插入一个数后然后要怎么样???说清楚了我帮你改!
补充:
#include <stdio.h>
#include <stdlib.h>
#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<N-1;i++)
printf("%5d",a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
补充:
#include <stdio.h>
#include <stdlib.h>
#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<N-1;i++)
printf("%5d",a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#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<N-1;i++)
printf("%5d",a[i]);
printf("\n");
/**********FOUND**********/
i=0;
while
(i<N-1&&number>=a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
#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<N-1;i++)
printf("%5d",a[i]);
printf("\n");
/**********FOUND**********/
i=0;
while
(i<N-1&&number>=a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#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<N-1;i++)
printf("%5d",a[i]);
printf("\n");
/**********FOUND**********/
i=0;
while
(i<N-1&&number>=a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
#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<N-1;i++)
printf("%5d",a[i]);
printf("\n");
/**********FOUND**********/
i=0;
while
(i<N-1&&number>=a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#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<N-1;i++)
printf("%5d",a[i]);
printf("\n");
/**********FOUND**********/
i=0;
while (i<N-1&&number>=a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
#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<N-1;i++)
printf("%5d",a[i]);
printf("\n");
/**********FOUND**********/
i=0;
while (i<N-1&&number>=a[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<N;i++)
printf("%5d",a[i]);
printf("\n");
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询