微信搜索关注"91考试网"公众号,领30元,获取公务员、事业编、教师等考试资料40G!
第26套题
一、程序填空题
#include <stdio.h>
double fun(int n)
{ int i; double s, t;
/**********found**********/
s=__1__;
/**********found**********/
for(i=1; i<=__2__; i++)
{ t=2.0*i;
/**********found**********/
s=s+(2.0*i-1)*(2.0*i+1)/__3__;
}
return s;
}
main()
{ int n=-1;
while(n<0)
{ printf("Please input(n>0): "); scanf("%d",&n); }
printf("\nThe result is: %f\n",fun(n));
}
二、程序改错题
#include <stdio.h>
int fun (char *str,char *substr)
{ int i,j,k,num=0;
/************found************/
for(i = 0, str[i], i++)
for(j=i,k=0;substr[k]==str[j];k++,j++)
/************found************/
If(substr[k+1]=='\0')
{ num++;
break;
}
return num;
}
main()
{
char str[80],substr[80];
printf("Input a string:") ;
gets(str);
printf("Input a substring:") ;
gets(substr);
printf("%d\n",fun(str,substr));
}
三、程序编写题
#include <stdio.h>
#include <math.h>
double fun ( double eps)
{
}
main( )
{ double x;void NONO ();
printf("Input eps:") ;
scanf("%lf",&x); printf("\neps = %lf, PI=%lf\n", x, fun(x));
NONO();
}
void NONO ()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *fp, *wf ;
int i ;
double x ;
fp = fopen("K:\\k01\\24010001\\in.dat","r") ;
wf = fopen("K:\\k01\\24010001\\out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(fp, "%lf", &x) ;
fprintf(wf, "%lf\n", fun(x)) ;
}
fclose(fp) ;
fclose(wf) ;
}