时间:2011-12-25 00:26:07
第28套题
一、程序填空题
#include <stdio.h>
double fun(double e)
{ int i, k; double s, t, x;
s=0; k=1; i=2;
/**********found**********/
x=__1__/4;
/**********found**********/
while(x __2__ e)
{ s=s+k*x;
k=k* (-1);
t=2*i;
/**********found**********/
x=__3__/(t*t);
i++;
}
return s;
}
main()
{ double e=1e-3;
printf("nThe result is: %fn",fun(e));
}
二、程序改错题
#include <stdio.h>
/************found************/
void fun ( int n )
{ int a, b, c, k; double s;
s = 0.0; a = 2; b = 1;
for ( k = 1; k <= n; k++ ) {
/************found************/
s = s + (Double)a / b;
c = a; a = a + b; b = c;
}
return s;
}
main( )
{ int n = 5;
printf( "nThe value of function is: %lfn", fun ( n ) );
}
三、程序编写题
#include <stdio.h>
#define M 4
int fun (int a[][M])
{
}
main( )
{ int arr[2][M]={5,8,3,45,76,-4,12,82} ;void NONO ();
printf("max =%dn", fun(arr)) ;
NONO( ) ;
}
void NONO ()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *wf ;
int arr[][M]={5,8,3,90,76,-4,12,82} ;
wf = fopen("K:\k01\24010001\out.dat","w") ;
fprintf(wf, "max=%dn", fun(arr)) ;
fclose(wf) ;