x+i
&x[i+1]
x+(i++)
&x[++i]
第1题:
请补充函数fun(),该函数的功能是:返回字符数组中指定子符的个数,指定字符从键盘输入。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
int fun (char s[],char ch)
{
int i=0, n=0;
while(【 】)
{
if(【 】)
n++;
i++;
}
【 】;
}
main ( )
{
int n;
char str[N], ch;
clrscr ();
printf ("\nInput a string: \n");
gets (str);
printf ("\nInput a charactor: \n" ;
scanf ("%c", &ch);
n=fun (str, ch);
printf("\nnumber of %c:%d", ch, n);
}
第2题:
在主函数中,从键盘输入若干个数放入数组x中,用0结束输入但不计入数组。下列给定程序中,函数fun()的功能是:输出数组元素中小于平均值的元素。请补充函数fun()。
例如:数组中元素的值依次为1,2,2,12,5,15,则程序的运行结果为1,2,2,5。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<conio.h>
include<stdio.h>
void fun( 【 】,int n)
{
double sum=0.0;
double average=0.0;
int i=0;
for(i=0;i<n;i++)
【 】;
average= 【 】;
for(i=0;i<n;i++)
if(x[i]<average)
{
if(i%5==0)
printf("\n");
printf("%d/",x[i]);
}
}
main()
{
int x[1000];
int i=0;
clrscr();
printf("\nPlease enter some data(end with 0):");
do
{
scanf("%d",&x[i]);
}
while(x[i++]!=0);
fun(x,i-1);
}
第3题:
程序定义了N×N的二维数组,并在主函数中自动赋值。
请编写函数fun(int a[][N],int n),该函数的功能是使数组左下半三角元素中的值加上n。
例如:若n的值为3,a数组中的值为
a=2 5 4
1 6 9
5 3 7
则返回主程序后a数组中的值应为
5 5 4
4 9 9
8 6 10
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数full的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include <conio.h>
include <stdlib.h>
define N 5
fun(int a[][N],int n)
{
}
main()
{
int a[N][N],n,i,j;
clrscr();
printf("***** The array *****\n");
for(i=0;i<N;i++)
/*产生—个随机5*5矩阵*/
{
for(j=0;j<N;j++)
{
a[i][j]=rand()%10;
printf("%4d",a[i][j]);
}
printf("\n");
}
do
n=rand()%10;
/*产生一个小于5的随机数n*/
while(n>=5);
printf("n=%4d\n",n);
fun(a,n);
printf("*****THE RESULT*****\n");
for(i=0;i<N;i++)
{
for(j=0;j<N;i++)
printf("%4d",a[i][j]);
printf("\n");
}
}
第4题:
下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun(),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如:若a数组中的值为
a= 0 1 2 7 9
1 9 7 4 5
2 3 8 3 1
4 5 6 8 2
5 9 1 4 1
则返回土程序后s的值应为3.375。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的仟何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include<conio.h>
include<stdlib.h>
define N 5
double fun (int w[] [N])
{
}
main()
{
int a[N] [N]={0,1,2,7,9,1,9,7,4,5,2,
3,8,3,1,4,5,6,8,2,5,9,1,4,1};
int i, j;
double s;
clrscr();
printf("*****The array*****\n ");
for (i=0; i<N; i++)
{ for (j=0;j<N;i++)
{printf("%4d ",a[i] [j]);}
printf("\n ");
}
s=fun(a);
printf("*****THE RESULT*****\n ");
printf("The sum is : %lf\n ",s);
}
第5题:
下列程序定义了NXN的二维数组,并在主函数中赋值。请编写函数fun(),函数的功能是求出数组周边元素的平方和并作为函数值返回给主函数中的S。例如:若a数组中的值为
a=0 1 2 7 9
1 11 21 5 5
2 21 6 11 1
9 7 9 10 2
5 4 1 4 1
则返回主程序后s的值应为310。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
include<conio.h>
include<stdlib.h>
define N 5
int fun (int w[][N])
{
}
main()
{
int a[N)[N]={0,1,2,7,9,1,1l,2l,5,5,2, 21,6,11,1,9,7,9,10,2,5,4,1,4,1};
int i,j;
int S;
clrscr( );
printf("*****The array***+*\n");
for (i=0; i<N; i++)
{for(j=0;j<N;i++)
{printf(“%4d”,a[i][j]);}
printf("\n");
}
s=fun(a);
printf(“*****THE RESULT*****\n”);
printf("The sum is:%d\n",s);
}
第6题:
以下函数的功能是:通过键盘输入数据,为数组中的所有元素赋值。 #include<stdio.h> #define N l0 void fun(int x[N]) {int i=O; while(i<N)scanf("%d",___ ); } 在程序中下划线处应填人的是( )。
A.x+i
B.&x[i+1]
C.x+(i++)
D.&x[++i]
第7题:
fun函数的功能是:通过键盘输入给x所指的整型数组所有元素赋值。在下划线处应填写的是
#include <stdio.h>
#define N 5
void fun(int x[N])
{ int m;
for(m=N-1;m>=0; m--) scanf(”%d”,__________);
}
A)&x[++m]
B) &X[m+1]
C)x+(m++)
D) x+m
第8题:
以下函数的功能是:通过键盘输入数据,为数组中的所有元素赋值。
#include<stdio.h>
#define N 10
void fun(int x[N])
{int i=0;
while(i<N)scanf(“%d”,_______);
}
在程序中下划线处应填入的是
A.x+i
B.&x[i+1]
C.x+(i++)
D.&x[++i]
第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题:
请编写一个函数void fun(int a [],int n),其中a为数组,n为数组a的长度。函数fun()的功能是冒泡排序法将数组a元素按从小到大的顺序排列,实现数组a的升序排列。
注意:部分源程序已存在文件PROC12.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。
文件PROC12.cpp的内容如下:
//PROC12. cpp
include <iostream>
using namespace std;
define MAX 100
void fun(int a[],int n);
int main ()
{
int a[MAX],n,i;
cout<<"Please enter the array size n:\n";
do {
cin>>n;
if (n>100)
cout<<"array size flowover! ReEnter a number(0-100)\n";
}while (n>100);
cout<<"Enter the array data:\n";
for (i=0; i<n; i++)
cin>>a [ii;
fun(a[],n);
for (i=0; i<n; i++)
cout<<a [i] <<" ";
cout<<end1;
return 0;
}
void fun(int a[ ],int n)
{
// * * * * * * * *
}
第11题:
程序定义了n×n的二维数组,并在主函数中自动赋值。请编写函数fun,该函数的功能是:使数组左下半三角元素中的值乘以n。
fun(int a[][n],int n)
{int i,j;
for(i=0;i
for(j=0;j<=i;j++)
a[j]=a[j]*n;}
第12题:
&x[++m]
&x[m+1]
x+(m++)
x+m
第13题:
请补充函数fun(),该函数的功能是;交换数组aa中最大和最小两个元素的位置,结果依然保存在原数组中,其它元素位置不变。注意数组aa中没有相同元素。
例如,输入“33,67,42,58,25,76,85,16,41, 56”,则输出“33,67,42,58,25,76,16,85,41,56”。
注意;部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio. h>
define N 10
void fun(int aa[])
{
int i, j, t;
int max=0, min=0;
for(i=0; i<N; i++)
{
if(【 】)
max=i;
if(【 】)
min=i;
}
t=aa [max];
【 】;
aa [min] =t;
}
main()
{
int i;
int aa [N] ={33, 67, 42,58,25, 76, 85,16, 41, 56};
clrscr ();
printf("\n*** original list ***\n");
for(i=0; i<N; i++)
printf ("%4d", aa [i] );
fun (aa);
printf ("\n*** new list ***\n");
for(i=0; i<N; i++)
printf ("%4d", aa [i]);
}
第14题:
请编一个函数void fun( int tt[M][N], int pp[N], tt指向一个M行N列的二维数组,求出二维数组每列中最大元素,并依次放入pp所指的一维数组中。二维数组中的数已在主函数中给出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
define M 3
define N 4
void fun(int tt[M][N],int pp[N])
{
}
main()
{
int t[M] [N]={{68,32,54,12},{14,24,88,
58},{42, 22, 44, 56}};
int p[N],i,j,k;
clrscr();
printf("The riginal data is:\n");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
printf("%6d",t[i][j]);
printf("\n");
}
fun(t,p);
printf("\nThe result is:\n");
for(k=0;k<N;k++)
printf("%4d",p[k]);
printf("\n");
}
第15题:
请编写一个函数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)
{
//* * * * * * * * *
}
第16题:
请编写函数fun(),函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
例如:若二维数组中的值为
1 3 5 7 9
2 9 9 9 4
6 9 9 9 8
1 3 5 7 0
则函数值为61。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
define M 4
define N 5
int fun( int a [M][N])
{
}
main()
{
int aa[M][N]={{1,3,5,7,9},{2,9,9,9,4},
{6,9,9,9,8},{1,3,5,7,0}};
int i, j, y;
clrscr();
printf ("The original data is :\n ");
for(i=0; i<N;i++)
{for (j=0; j<N;j++)
printf("%6d ",aa[i][j]);
printf("\n ");
}
y=fun(aa);
printf("\nThe sun:%d\n ",y);
printf("\n");
}
第17题:
下列程序定义了N×N的二维数组,并在主函数中自动赋值;请编写函数fun(int a[][N]),该函数的功能是:使数组左下半三角元素中的值全部置成0。例如a数组中的值为
a=1 9 7
2 3 8
4 5 6
则返回主程序后a数组中的值应为
0 9 7
0 0 8
0 0 0
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <stdlib.h>
define N 5
int fun (int a[] [N])
{
}
main()
{
int a[N] [N],i,j;
clrscr();
printf("*****The array*****\n");
for(i=0;i<N;i++)
/*产生—个随机的5*5矩阵*/
{ for(j=0;j<N;j++)
{a[i][j]=rand()%10;
printf("%4d", a[i][j]);
}
printf("\n");
}
fun (a);
printf("THE RESULT\n");
for(i=0;i<N;i++)
{ for(j=0;j<N;j++)
printf("%4d",a[i][j));
printf("\n");
}
}
第18题:
fun函数的功能是:通过键盘输入给x所指的整型数组所有元素赋值。在下划线处应填写的是( )。 #include<stdio.h> #define N 5 void fun(int x[N]) { int m; for(m=N-t;m>=O;m-)scanf("%d",____); }
A.%&X[++m]
B.&x[m+1]
C.x+(m++)
D.x+m
第19题:
下列程序中函数fun的功能是:统计person所指结构体数组中所有性别(sex)为M的记录的个数,存入变量n中,并作为函数值返回。请填空。
include <stdio.h>
define N 3
typedef struct
{ int num; char nam[10]; char sex;} SS;
int fun(SS person[])
{ int i,n=0;
for(i=0; i<N; i++)
if(【 】=='M') n++;
return n;
}
main()
{ SS W[N]={{1,"AA",'F'},{2,"BB",'M'},{3,"CC",'M'}}; int n;
n=fun(W); printf("n=%d\n", n);
}
第20题:
下列程序定义了N×N的二维数组,并在主函数中赋值。请编写一个函数fun(),函数的功能是:求数组周边元素的平方和并作为函数值返回给主函数。例如,若数组a中的值为
0 1 2 7 9
1 11 21 5 5
2 21 6 11 1
9 7 9 10 2
5 4 1 4 1
则返回主程序后s的值应为310。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
[试题源程序]
include <stdio.h>
include <conio.h>
include <stdlib.h>
define N 5
int fun(int w[][N])
{
}
main()
{
int a[N][N]={0, 1, 2, 7, 9, 1, 11, 21, 5, 5, 2, 21, 6, 11, 1, 9, 7, 9, 10, 2, 5, 4, 1, 4, 1};
int i, j;
int s;
clrscr()
printf("*****The array*****\n");
for(i=0; i<N; i++)
{
for(j=0; j<N; j++)
{
printf("%4d", a[i][j]);
}
printf("\n');
}
s=fun(a);
printf("*****THE RESULT*****\n");
printf("The sum is: %d\n", s);
}
第21题:
请补充函数fun(),该函数的功能是:把数组aa中元素下标为偶数的元素按从小到大重新保存在原数组中,其它元素位置不变。
例如,输入“33,67,42,58,25,76,85,16,41, 56”,则输出“25,67,33,58,41,76,42,16,85,56”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<s tdio. h>
define N 10
void fun(int aa[])
{
int i, j, t;
for (i=0; i<N;i=i+2)
{
for(【 】; j<N; j=j+2)
if (【 】)
{
t=aa [j];
aa [j] =aa [i];
aa [i] =t;
}
}
}
main ()
{
int i;
int aa[N]={33, 67,42, 58, 25, 76, 85, 16,
41, 56};
clrscr ();
printf("\n*** original list ***\n");
for(i=0; i<N; i++)
printf ("%4d", aa [i] );
fun (aa);
printf("\n*** new list ***\n");
for(i=0; i<N; i++)
printf ("%4d", aa [i] );
}
第22题:
以下函数的功能是:通过键盘输入数据,为数组中的所有元素赋值。
#include
#define N 10
void fun(int x[N])
{ int i=0;
while(i<>
}
在程序中下划线处应填入的是
A.x+i
B.&x[i+1]
C.x+(i++)
D.&x[++i]
第23题:
试题14
以下程序调用fun函数把x中的值插入到a数组下标为k的数组元素中。主函数中,n存放a数组中数据的个数。请填空。
#include <stdio.h>
void fun(int s[], int *n, int k, int x)
{ int i;
for(i=*n-1; i>=k; i- - ) s[ ___ ]=s[i];
s[k]=x;
*n=*n+______;
}
main()
{ int a[20]={1,2,3,4,5,6,7,8,9,10,11}, i, x=0, k=6, n=11;
fun(a, &n, k, x);
for(i=0; i<n; i++) printf(“%4d”,a[i]); printf(“\n”);
}