题目
例如,一维数组中的数据是:2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10。
删除后,数组中的内容应该是:2 3 4 5 6 7 8 9 10。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第1题
请编写函数fun(),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:
2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10
删除后,数组中的内容应该是:
2 3 4 5 6 7 8 9 10。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio. h>
define N 80
int fun(int a[], int n)
{
}
main ()
{
int a[N]={ 2,2,2,3,4,4,5,6,6,6,6,7,7,
8,9,9,10,10,10,10}, i, n=20;
printf ("The original data : \n");
for(i=0; i<n; i++)
printf ("%3d", a [i] );
n=fun (a, n);
printf("\n\nThe data after deleted
: \n");
for(i=0; i<n; i++)
printf ("%3d", a [i] );
printf ("\n\n");
}
第2题
请补充函数fun(),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:1,1,1,2,2,2,3, 4,4,5,5,6,6,7,7,8,9,9,10,10。
删除后,数组中的内容应该是:1,2,3,4,5,6,7, 8,9,10。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
define N 80
int fun(int a[],int n)
{
int i, t,j=0;
t=a[0];
for(i=1;i<n;i++)
if(【 】)
;
else
{
【 】;
t=a[i];
}
a[j++]=t;
return j;
}
main()
{
int a[N]={1,1,2,2,2,3,4,4,5,5,6,6,6,
7,7,8,9,9,10,10},i,n=20;
printf("The original data:\n");
for(i=0; i<n; i++)
printf("%4d",a[i]);
n=fun(a,n);
printf("\n\nThe data after deleted ;
\n");
for (i=0;i<n;i++)
printf("%4d",a[i]);
printf("\n");
}
第3题
请编写函数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的花括号中填入你编写的若干语句。
第4题
请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p到n-1(p≤n-1)的数组元素平移到数组的前面。
例如,一维数组中的原始内容为1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15,p的值为6。移动后,一维数组中的内容应为7,8,9,10, 11,12,13,14,15,1, 2, 3, 4, 5, 6。
注意:部分源程序给出如下。
请勿改动主函数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");
}
第5题
请编写函数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");
}
第6题
请编写函数fun(),该函数的功能是将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。
例如:二维数组中的数据为
33333333
44444444
55555555
则一维数组中的内容应是
334455334455334455334455。
注意:部分源程序以存在文件test_2.cpp中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
文件test39_2.cpp的内容如下:
include<stdio.h>
include<iostream.h>
void fun(int(*s) [10],int *b, int *n,int mm,int nn)
{
}
void main()
{
int w[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j;
int a[100]={0}, n=0;
cout<<"The matrix:\n"
for(i=0; i<3; i++)
{
for(j=0; j<4; j++
cout<<w[i] [j];
cout<<endl;
}
fun(w, a, &n, 3, 4);
cout<<"The A array:\n";
for(i=0; i<n; i++)
cout<<a[i];
cout<<"\n\n";
}
第7题
请编写函数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]);
}
第8题
请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p~n-1(p<n-1)的数组元素平移到数组的前面。
例如,一维数组中的原始内容为1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, P的值为6。移动后,一维数组的内容应为7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
[试题源程序]
inciude <stdio.h>
define N 80
void fun(int *w, int p, int n)
{
}
main()
{
int a[N]=(i, 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");
}
第9题
请编写一个函数fun(),它的功能是:找出一维数组元素中最大的值和它所在的下标,最大值和它所在的下标通过形参传回。数组元素中的值已在主函数中赋予。
主函数中x是数组名,n是x中的数据个数,max存放最大值,index存放最大值所在元素的下标。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdlib.h>
include<stdio.h>
void fun(int a[],int n, int *max,int *d)
{
}
main()
{
int i, x[20], max, index, n=10;
randomize();
for(i=0; i<=n; i++)
{
x[i]=rand()%50;
printf("%4d",x[i]);
/*输出一个随机数组*/
}
printf("\n");
fun(x,n,&max,&index);
printf("Max=%5d,Index=%4d\n",max,index);
}
第10题
请补充函数fun(),该函数的功能是求一维数组x[N]的平均值,并对所得结果进行四舍五入(保留两位小数)。
例如:当x[10]={15.6, 19.9, 16.7, 15.2, 18.3, 12.1, 15.5,11.0, 10.0, 16.0},结果为:avg=15.030000。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仪在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
double fun(double x[10])
{
int i;
long t;
double avg=0.0;
double sum=0.0;
for(i=0;i<l0;i++)
【 】;
avg=sum/10;
avg=【 】;
t=【 】;
avg=(double)t/100;
return avg;
}
main()
{
double avg,x[10]={15.6,19.9,16.7,15.2,18.3,12.1,15.5,11.0,10.0,16.0};
int i;
clrscr();
printf(“\nThe original data is:\n”);
for(i=0;i<l0;i++)
printf("%6.lf",x[i]);
printf(“\n\n”);
avg=fun(x);
printf(“average=%f\n\n”,avg);
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!