C语言程序改错:功能:在一个已按升序排列的数组中插入一个数,插入后,数 组元素仍按升序排列。
#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");
} 展开
2个回答
展开全部
#include <stdio.h>#define N 11void main(){ int i,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");/**********FOUND**********/ for(i=N-1;i>=0;i--) if(number<=a[i])/**********FOUND**********/ a[i+1]=a[i]; else { a[i+1]=number;/**********FOUND**********/ break; } if(number<a[0]) a[0]=number; printf("The result array:\n"); for(i=0;i<N;i++) printf("%5d",a[i]); printf("\n");}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询