int s[10]={0,1,2,3,4,5,6,7,8,9}; 这个s[]是定长的,s[0],s[9]就是边界,虽然C99增加了变长数组但也不是象你这么随心用的.问一下,你为什么不试试s[-1]
2018-04-01 14:37
2018-04-01 14:37
2018-04-01 14:43
2018-04-01 14:47
2018-04-01 15:43
2018-04-01 16:42
2018-04-01 19:20
2018-04-01 19:22
程序代码:
#include<stdio.h>
#include<stdlib.h>
void inserer(int *s,int x,int *n){
int i,j=0;
while(j<*n && s[j]<x) j++;
for(i=(*n)-1;i>=j;i--) s[i+1]=s[i];
s[i]=x;
printf("j = %d ,i = %d \n ",j,i);//你看看是不是一样?你怎么这么宁?
*n=(*n)+1;
}
void output(int *s,int *n){
int i; for(i=0;i<*n;i++) printf("%d ",s[i]);
printf("\n");
}
int main(void){
int s[10]={1,6,7,10,14,18,22,29,36,47},x;
int n=10; printf("Entrez un chiffre : ");
scanf("%d",&x);
printf("Le tableau precedent : ");
output(s,&n);
inserer(s,x,&n);//少分号
printf("Le nouveau tableau : ");
output(s,&n);
return EXIT_SUCCESS;
}
Entrez un chiffre : 12
Le tableau precedent : 1 6 7 10 14 18 22 29 36 47
j = 4 ,i = 3
Le nouveau tableau : 1 6 7 12 14 14 18 22 29 36 47
请按任意键继续. . .
2018-04-01 20:19
2018-04-01 20:23