求助。为什么这个程序运行不了?
#include <stdio.h>#define maxsize 100
int list[maxsize];
int n;
/*insert in a seqlist*/
int sq_insert(int list[],int *p_n,int i,int x)
{
int j;
if(i<0||i>*p_n)
return 1;
if(*p_n>=maxsize)
return 2;
for(j=*p_n;j>=i;j--)
list[j+1]=list[j];
list[i]=x;
(*p_n)++;
return 0;
}
/*delete in a seqlist*/
int sq_delete( int list[],int *p_n,int i)
{
int j;
if(i<0||i>*p_n)
return 1;
for(j=i+1;j<=*p_n;j++)
list[j-1]=list[j];
(*p_n)-- ;
return 0;
}
void main()
{
int i,x,temp;
printf("please input the number for n\n");
printf("n=");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf("list[%d]=",i);
scanf("%d",&list[i]);
}
printf("the list before insertion is\n");
for (i=0;i<=n;i++)
printf("%d",list[i]);
printf("\n");
printf("please input the position where you want to insert a value\n position=");
scanf("%d",&i);
printf("please input the value you want to insert.\n x=");
scanf("%d",&x);
temp=sq_insert(list, &n, i, x);
switch(temp)
{
case 0:printf("the insertion is successful!\n");
printf("the list after insertion is\n");
for(i=0;i<=n;i++)
printf("%d",list[i]);
printf("\n");
printf("the list's length is %d",n);
break;
case 1:
case 2:printf("the insertion is not successful!\n");
break;
}
temp=sq_delete( list,&n, i);
switch(temp)
{
case 0:printf("the deletion is successful!\n");
printf("the list after deletion is\n");
for(i=0;i<=n;i++)
printf("%d",list[i]);
printf("the list's length is %d",n);
break;
case 1:printf("the deletion is not successful!\n");
break;
}
}
运行时,输入数组,长度和插入的数后,就结束了。这是怎么回事?