编程题:
70.编写函数九n,它的功能是:计算并输出下列级数和:
例如,当n=10时,函数值为0.909091。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
#include
double fun( int n )
{
}
main()
{
clrscr();
printf(“%f\n”,fun(10));
}
74.学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:把分数最低的学生数据放在h所指的数组中,注意:分数最低的学生可能不止一个,函数返回分数最低的学生的人数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
#define N 16
typedef struct
{
char num[10];
int s;
} STREC;
int fun ( STREC *a, STREC *b )
{
}
main ()
{
STREC s[N]= {{“GA05″,85}, {“GA03″,76}, {“GA02″,69}, {“GA04″,85},
{“GA01″,91}, {“GA07″,72}, {“GA08″,64}, {“GA06″, 87},
{“GA015″,85}, {“GA013″,91}, {“GA012″,64}, {“GA014″,91},
{“GA011″,91}, {“GA017″,64}, {“GA018″,64}, {“GA016″,72}};
STREC h[N];
int i, n;
FILE *out;
n=fun ( s, h );
printf (“The %d lowest score :\n”, n);
for (i=0; i printf (“%s %4d\n”, h[i]. num, h[i]. s); printf (“\n”); out=fopen (“out14.dat”, “w”); fprintf (out, “%d\n”, n); for (i=0; i fprintf (out, “%4d\n”, h[i].s); fclose (out ); } 改错题: 34.下列给定程序中函数fun的功能是:将长整型数中每一位上为奇数的数依次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。例如,当s中的数为87653142时,t中的数为7531。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include #include void fun(long s,long *t) { int d; long s1=1; /********found********/ t = 0; while ( s>0) { d = s%10; /********found********/ if(d%2==0) { *t = d * s1 + *t; s1*=10; } s/=10; } } main() { long s, t; clrscr(); printf(“\nPlease enter s: “); scanf(“%ld”, &s); fun(s, &t); printf(“The result is: %ld\n”, t); } 36.下列给定程序中,函数fun的功能是:求三个数的最小公倍数。例如,给变量x1、x2、x3分别输入15 11 2,则输出结果应当是330。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include int fun(int x,int y,int z) { int j,t,n,m; /********found********/ j=1; t=m=n=1; /********found********/ while(t!=0&&m!=0&&n!=0) { j = j+1; t=j%x; m=j%y; n=j%z; } return j; } main( ) { int x1,x2,x3,j ; printf(“Input x1 x2 x3: “); scanf(“%d%d%d”,&x1,&x2,&x3); printf(“x1=%d, x2=%d, x3=%d \n”,x1,x2,x3); j=fun(x1,x2,x3); printf(“The minimal common multiple is : %d\n”,j); }