请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从0到p(p≤n-1)的数组元素平移到数组的最后。
例如,一维数组中的原始内容为1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15,p的值为3。移动后,一维数组中的内容应为5,6,7,8,9,10,11,12,13,14,15, 1, 2, 3, 4。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
define N 80
void fun(int *w, int p, int n)
{
}
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");
}
第1题:
请编写一个函数void fun(int p[],int n,int c),其中数组p的元素按由小到大的顺序排列,其元素个数为n。函数fun()的功能是将c插入到数组p中,且保持数组的升序排列。
注意:部分源程序已存在文件PROC9.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句;
文件PROC9.cpp的内容如下:
//PROC9.cpp
include <iostream>
include <string>
using namespace std;
define M 30
void fun(int p[ ],int n,int c);
int main ()
{
int pp[M],n,i;
int fg, c;
cout<<"Please input n:\n";
cin>>n;
cout<<"Please input the n data:\n";
for (i=0; i<n; i++)
cin>>pp [i];
cout<<"Please input c:\n";
cin>>c;
fun (pp, n, c);
for (i=0; i<n; i++)
cout<<pp [i] << " " ;
cout<<end1;
return 0;
}
void fun(int p[ ],int n, int c)
{
//* * * * * * * * *
}
第2题:
请编写函数fun,函数的功能是:移动一维数组中的内容:若数组中有n个整数,要求把下标从0到p(含p,p小于等于n-1)的数组元素平移到数组的最后。
例如,一维数组中的原始内容为:1,2,3,4,5,6,7,8,9,10:p的值为3。移动后,一维数组中的内容应为:5, 6, 7, 8, 9, 10, 1, 2, 3,4。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第3题:
有一个数组,内放N个整数,要求编写函数int processor(int *p)找出最小的数和它的下标,然后把它和数组中最前面的元素调换,下标返回给主函数输出,原始数组和改变后的数组由void output(int *p) 输出。
第4题:
请编写函数fun(),它的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从0到p(含p,p<n-1)的数组元素平移到数组的最后。例如:一维数组中的原始内容为:1,2,3,4,5,6,7,8,9,10;p的值为3。移动后,一维数组中的内容应为: 5,6,7,8,9,10,1,2,3,4。部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
include<stdiO.h>
define N 80
void fun(int *w,int p,int n)
{
}
main()
{in[ a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int i,p,n=15;
printf("The odginal data:\n");
for(i=0;i<n;i++)printf("%3d",a[i]);
printf("\nEnter p:");
scanf("%d",&p);
fun(a,p,n);
printf ("\n The data after moving:\n");
for(i=0;i<n;i++)printf("%3d”,a[i]);
}
第5题:
(11)己知a所指的数组中有N个元素。函数fun的功能是,将下标k(k>0)开始的后续元素全部向前移动一个位置。请填空。
void fun(int a[N],int k)
{ int i;
for(i=k;i<N;i++) a[ 【11】 ]=a[i];
}