这是什么问题,帮忙看看吧.
/*移动一维数组中的内容,若数组中有n个整数,要求把下标从p到n-1(p≤n-1)的数组元素平移到数组的前面。*/#include <stdio.h>
#define N 80
void fun(int *w, int p, int n)
{
int i = 0,b = 0;
for (i = p;i < n;i++)
{
b = w[i];
w[i] = w[i - p];
w[i - p] = b;
}
}
main()
{
int a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int i, p, n=15;
printf("The original data:\n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("\n\nEnter p: ");
scanf("%d",&p);
fun(a,p,n);
printf("\nThe data after moving:\n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("\n\n");
}
输入P是6,为什么输出会是7,8,9...15,4,5,6,1,2,3
最后这六个数的顺序怎么是这样啊.不应该是1,2,3,4,5,6么