第1题:
请编写函数fun(),其功能是;计算井输出下列多项式值。
S=(1-1/2)+(1/3-1/4)+…+(1/(2n-1)-1/2n)
例如,若主函数从键盘给n输入8后,则输出为 S-0.662872。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序;
include<stdio. h>
double fun(int n)
{
}
main ()
{
int n;
double s;
printf("\nInput n: ");
scanf ("%d", &n);
s=fun (n);
printf ("\ns=%f\n ", s);
}
第2题:
请编写函数fun(),它的功能是计算下列级数和,和值由函数值返回。
S=1+x+x2/2!3/3!+…/xn/n!
例如,当n=10,x=0.3时,函数值为1349859。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
include<math.h>
double fun(double x, int n)
{
}
main ()
{
clrscr ();
printf ("%f ",fun(0,3,10));
}
第3题:
请补充函数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);
}
第4题:
请编写函数fun,它的功能是:计算并输出n(包括n)以内能被5或9整除的所有自然数的倒数之和。
例如,在主函数中从键盘给n输入20后,输出为:s=0.583333。注意:要求n的值不大于100。
部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第5题:
编写函数fun(),函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。
S=1+1/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)
例如:若n的值为11时,函数的值为1.833333。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
float fun(int n)
{
}
main()
{
int n;
float s;
clrscr();
printf("\nPlease enter N: ");
scanf("%d",&n);
s=fun(n);
printf("The result is:%f\n " , s);
}
第6题:
以下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];
}
第7题:
请编写函数fun(),其功能是:计算并输出下列多项式的值。
S=1+4/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)
例如,着主函数从键盘给n输入50后,则输出为 S=1.960784。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
double fun(int n)
{
}
main ()
{
int n;
double s;
printf ("\nInput n: ");
scanf ("%d", &n);
s=fun (n);
printf ("\n\ns=%f\n\n", s);
}
第8题:
请编写函数fun(),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如x有5门课程的成绩是90.5,72,80,61.5,55,则函数的值为71.80。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
float fun (float *a, int n)
{
}
main ()
{
float score[30]=(90.5,72,80,61.5,55},
aver;
aver=fun(score, 5);
printf("\nAverage score is: %5.2f
\n",aver);
}
第9题:
请编写函数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");
}
第10题:
请编写函数fun(),它的功能是求Fibonacci数列中小于t的最大的一个数,结果由函数返回。其中Fibonacci数列F(n)的定义为
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如:t=1000时,函数值为987。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <math.h>
include <stdio.h>
int fun(int t)
{
}
main()
{
int n;
clrscr();
n=1000;
printf("n=%d, f=%d\n",n, fun(n));
}