题目内容:
请编写函数proc(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从P到n-1(p≤n-1)的数组元素平移到数组的前面。 例如,一维数组中的原始内容为1,2,3,4,5,6,7,8,9,10,11,12,13,14,p的值为4。移动后,一维数组中的内容应为5,6,7,8,9,10,11,12,13,14,1,2,3,4。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define M 80
void proc(int * w,int P,int n)
{ }
void main()
{
int arr[M]={1,2,3,4,5,6,7,8,9,10,11,12,13,14};
int i,p,n=14;
printf("The original data:\n");
for(i=0:i<n;i++)
printf("%3d",arr[i]);
printf("\n\nEnter P:");
scanf("%d",&p);
proc(arr,p,n);
printf("\nThe data after moving:\n");
for(i=0:i<n,i++)
printf("%3d",arr[i]);
printf("\n\n");
}
参考答案:
答案解析: