2012全国计算机二级C语言(C++)题库 第26套题

时间:2011-12-25 00:22:58

微信搜索关注"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: %fn",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]=='')

       {  num++;

          break;

       }

   return num;

}

 

main()

{

  char str[80],substr[80];

  printf("Input a string:") ;

  gets(str);

  printf("Input a substring:") ;

  gets(substr);

  printf("%dn",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=%lfn", 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, "%lfn", fun(x)) ;

  }

  fclose(fp) ;

  fclose(wf) ;

}

 


微信搜索关注"91考试网"公众号,领30元,获取公务员事业编教师考试资料40G
【省市县地区导航】【考试题库导航】

电脑版  |  手机版  |  返回顶部