A.s*i
B.s*a
C.s+i*i
D.s+a*a
第1题:
函数fun的功能是:根据以下公式求p的值,结果由函数值返回。m与n为两个正数且要求m>n。
例如:m=12,n=8时,运行结果应该是495.000000。请在题目的空白处填写适当的程序语句,将该程序补充完整。
#include
#include
float fun (int m, int n)
{ int i;
double p=1.0;
for(i=1;i<=m;i++)( );
for(i=1;i<=n;i++)( );
for(i=1;i<=m-n;i++)p=p/i;
return p;}
main ()
{ clrscr();
printf ("p=%f\n",fun (12,8));}
第2题:
请补充函数fun(),该函数的功能是:计算N×N维矩阵元素的方差,结果由函数返回。维数N在主函数中输入。例如:

注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
include <conio.h>
include <stdlib.h>
include <math.h>
define N 20
double fun(【 】,int n)
{
int i,j;
int k;
double s=0.0;
double f=0.0;
double aver=0.0;
double sd=0.0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
s+=a[i][j];
aver=【 】;
for(i=0;i<n;i++)
for(j=0;i<n;j++)
f+=(a[i][j]-aver)*(a[i][j]-aver);
f/(n*n);
sd=【 】;
return sd;
}
main()
{
int a[N][N];
int n;
int i,j;
double s;
clrscr();
printf("***+Input the dimension of
array N*****\n");
scanf("%d",&n);
printf("***** The array *****\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=rand()%50;
while(a[i][j]=0)
a[i][j]=rand()%60;
printf("%4d",a[i][j]);
}
printf("\n\n");
}
s=fun(a,n);
printf("******* THE RESULT *******\n");
printf("%4.3f\n",s);
}
第3题:
以下fun函数的功能是:找出具有N个元素的一维数组中的最小值,并作为函数值返回,请填空。(设N己定义)
int fun(int x[N])
{int i,k=0
for(i=0;i<N;i++)
if(x[i]<x[k])k=_____;
return x[k];
}
第4题:
学生的记录由学号和成绩组成,N名学生的数据已存放在主函数的结构体数组s中,请编写函数fun,它的功能是:把低于平均分的学生数据放在b所指的数组中,低于平均分的学生人数通过形参n传回,平均分通过函数值返回。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的花括号中填入所编写的若干语句。
[试题源程序]
include<stdio.h>
define N 8
typedef struct
{
char num[10];
double s;
}STREC;
double fun(STREC *a, STREC *b, int *n)
{
}
void main()
{
STREC s[N]={{"GA05", 85},
{"GA03", 76}, {"GA02", 69}, {"GA04", 85},
{"GA01", 91}, {"GA07", 72}, {"GA08", 64},
{"GA06", 87}};
STREC h[N], t; FILE *out;
int i, j, n;
double ave;
ave=fun(s, h, &n);
printf("The %d student data which is lower than %7.3 f:\n", n, ave);
for(i=0; i<n; i++)
printf("%s %4.1f\n", h[i]. num, h[i].s);
printf("\n");
ut=fopen("out.dat", "W");
fprintf(out, "%d\n%7.3f\n", n, ave);
for(i=0; 2<n-1; i++)
for(j=i+1; j<n; j++)
if(h[i]. s>h[j].s)
{
t=h[i];
h[i]=h[j];
h[j]=t;
}
for(i=0; 2<n; i++)
fprintf(out, "%4.1f\n", h[i].s);
fclose(out);
}
第5题:
设在主函数中有以下定义和函数调用语句,且fun()函数为void类型,请写出fun()函数的首部______。
int main()
{
double s[10][22];
int n:
...
fun (s):
...
return 0;
}
第6题:
阅读下列函数说明和C代码,将应填入 处的字句写在答题纸的对应栏内。
[函数1.1说明]
函数int factors(int n)的功能是判断整数n(n>=2)是否为完全数。如果n是完全数,则函数返回0,否则返回-1。
所谓“完全数”是指整数n的所有因子(不包括n)之和等于n自身。例如28的因子为1、2、4、7、14,而28=1+2+4+7+14,因此28是“完全数”。
[函数1.1]
int factors(int n)
{
int i,s;
for(i=1,s=0;i<=n/2;i++)
if(n%i==0) (1) ;
if( (2) )return 0;
return -1;
}
[函数1.2说明]
函数int maxint(int a[], int k)的功能是用递归方法求指定数组中前k个元素的最大值,并作为函数值返回。
[函数1.2]
int maxint(int a[],int k)
{
int t;
if( (3) ) return (4) ;
t=maxint(a+1, (5) );
return (a[0]>t)?a[0]:t;
第7题:
若有以下函数首部 int fun(double x[lO],int *n) 则下面针对此函数的函数声明语句中正确的是______。
A.int fun(double x, int *n);
B.int fun(double, int);
C.int fun(double *x, int n);
D.iht fun(double*,int*);
第8题:
请编写函数fun(),它的功能是计算:s=(1-In(1)-In(2)-In(3)-…-1n(m))2
s作为函数值返回。
在C语言中可调用log(n)函数求In(n)。log函数的引用说明是double log(double x)。
例如,若m的值为15,则fun()函数值为723.570801。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <math.h>
double fun(int m)
{
}
main()
{
clrscr();
printf("%f\n",fun(15));
}
第9题:
下列给定程序中,函数fun()的功能是:计算
S=f(-n)+f(-n+1)+…+f(0)+f(1)+f(2)+…f(n)的值。
例如,当n为5时,函数值应为10.407143。f(x)函数定义如下:

请改正程序中的错误,使它能得山正确的结果。
注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio. h>
include <stdio. h>
include <math. h>
/**************found***************/
f (double x)
{
if (x==0.0 || x==2.0)
return 0.0;
else if (x<0.0)
return (x-1) / (x-2);
else
return (x+1) / (x-2);
}
double fun(int n)
{
int i; double s=0.0,y;
for (i=-n; i<=n; i++)
{ y=f(1.0*i); s+=y;}
/**************found**************/
return s
}
main()
{ clrscr();
printf ("%f\n", fun (5));
}
第10题:
请补充函数fun(),该函数的功能是计算下面公式SN的值:

例如:当N=50时,SN=71.433699。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<conio.h>
include<stdio.h>
double fun(int n)
{
double s=1.0,S1=0.0;
int k;
for(【l】;k<=n;k++)
{
s1=s;
【 】;
}
return【 】;
}
main()
{
int k=0;
double S;
clrscr();
printf("\nPlease input N=");
scanf("%d",&k);
s=fun(k);
printf("\ns=%lf",s);
}
。第三空:变量s存放最后的结果,所以函数的返回值是s的值。
第11题:
第12题:
s*i
s*a
s+i*i
s+a*a
第13题:
学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fjun(),该函数的功能是:把高于等于平均分的学生数据放在b所指的数组中,高于等于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
define N 12
typede f struct
{ char num[10];
double s;
} STREC;
double fun (STREC *a,STREC *b, int *n)
{
}
main ( )
STREC s IN] = { { "GA05", 85 }, { "GA03", 76 },
{"GA02", 69}, {"GA04", 85}, {"GA01", 91},
{"GA07", 72}, {"GA08", 64}, {"GA06", 87},
{"GA09", 60}, { "GAll", 79 }, { "GA12", 73},
{"GA10", 90 } };
STREC h[N],t;
FILE *out;
int i ,j,n;
double ave;
ave=fun (s, h, &n);
printf("The %d student data which is
higher than %7.3f: In", n, ave);
for(i=0; i<n; i++)
printf ("%s %4.1f\n",h[i] .num, h[i] .s);
printf ("\n");
out=fopen ("out90.dat", "w");
fprintf(out, "%dkn %7.3f\n",n,ave);
for(i=0; i<n-1; i++)
for (j=i+l; j<n; j ++)
if (h[i] .s<h[j ] .s)
{t=h Ii] ;h[i]=h[j] ;h[j]=t; }
/*分数从高到低排列*/
for(i=0; i<n; i++)
fprintf(out, "%4.1f\n",h[i] .s);
fclose (out);
}
第14题:
请补充函数fun,其功能是:计算并输出给定10个数的方差:

例如,给定的10个数为15.0,19.0,16.0,15.0,18.0,12.0, 15.0,11.0,10.0,16.0,输出为s=2.758623。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<math. h>
double fun (double x[10])
{
int i;
double avg=0.0;
double sum=0.0;
double abs=0.0;
double sd;
for (i=0; i<10; i++)
【 】;
avg=sum/10;
for(i=0;i<10;i++)
【 】;
sd=【 】;
return sd;
}
main()
{
double s,x[10]={15.0,19.0,16.0,15.0,
18.0,12.0,15.0,11.0,10.0,16.0};
int i;
printf("\nThe original data is :\n");
for(i=0;i<10;i++)
printf("%6.1f",x[i]);
printf("\n\n");
s=fun(x);
printf("s=%f\n\n",s);
}
第15题:
下列程序定义了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);
}
第16题:
阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明]
编写一个函数,输入为偶数时,调用函数求1/2+?/+…+1/n,当输入n为奇数时,调用函数1/1+1/3+…+1/n (利用指针函数)。
[函数]
include "stdio. h",
main()
{
float peven (),podd (),dcall ();
float sum;
int n;
while (1)
{
scanf("%d",&n);
if (n>1)
break;
}
if(n%2==0)
{
printf("Even="):
(1);
}
else
{
pfinff("Odd=");
(2);
}
printf("%f",sum);
}
float peven (int n)
{
float s;
int i
s=1;
for(i=2;i<=n;i+=2)
(3);
return (s);
}
float podd (n)
int n;
{
float s;
int i;
s=0;
for(i=1 i<=n;i+=2)
(4);
return (s);
}
float dcall(fp,n)
float (*fp) ();
int n;
{
float s;
(5);
returu (s);
}
第17题:
若有以下函数首部: int fun(double x[10],int *n) 则下面针对此函数的函数声明语句中正确的是( )。
A.int fun(double x, int *n);
B.int fun(double, int);
C.int fun(double *x, int n);
D.int fun(double*, int*);
第18题:
以下函数的功能是:求x的y次方,请填空。double fun(double x,int y){ int i; double z; for(i=1,z=x;i<y;i++) z=z*; return z;}
第19题:
请编写函数fun(),其功能是:计算并输出给定10个数的方差。

其中

例如,给定的10个数为95.0,89.0,76.0,65.0,88.0, 72.0,85.0,81.0,90.0,56.0,则输出为S=11.730729。
注意;部分源程序给出如下.
请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<math.h>
include<stdio.h>
double fun(double x[10])
{
}
main()
{
double s,x[i0]={95.0,89.0,76.0,65.0,
88.0,72.0,85.0,81.0,90.0,56.0};
int i;
printf("\nThe original data is:\n");
for(i=0;i<10;i++)
printf("%6.1f ",x[i]);
printf("\n\n ");
s=fun(x);
printf("s=%f\n\n ",s);
}
第20题:
以下sum函数的功能是计算下列级数之和:

请给函数中的各变量正确赋初值。
double sum(douLle x,int n)
{ int i;
double a,b,s;
【 】
for(i=1;i<=n;i++) {a=a*x;b=b*i;s=s+a/b;}
return s;
}
第21题:
请编写函数fun(),该函数的功能是:计算并输出
S=1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+n0.5)
例如,若主函数从键盘给n输入20后,则输出为
s=534.188884。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include <math. h>
include <stdio. h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\n\nInput n: ");
scanf ("%d", &n);
s=fun (n)
printf ("\n\ns=%f\n\n", s);
}
第22题:
请补充函数fun(),该函数的功能是:输出一个N×N矩阵,N由键盘输入,矩阵元素的值为随机数,并计算出该矩阵四周边元素的平均值,结果由函数返回。例如:当N=4时:

注章:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序;
include<stdio.h>
include<conio.h>
include<stdlib.h>
define N 20
double fun(int a[ ][N],int n)
{
int i,j;
int k;
double s=0.0;
double aver=0.0;
printf("*****The array*****\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=rand()%10;
printf("%4d",a[i][j]);
if(【 】)
s+=a[i][j];
}
printf("\n");
}
k=【 】;
aver=【 】;
return aver;
}
main( )
{
int a[N][N];
int n;
double S;
Clrscr( );
printf("*****Input the dimension Of array N*****\n");
scanf(“%d”,&n);
S=fun(a,n);
printf(“***** THE RESULT *****\n”);
printf(“The average is %2,3f\n”,S);
}
第23题:
int fun(double*,int*);
int fun(double,int);
int fun(double *x,int n);
int fun(double x,int*n);